gosu - 访问辅助实体的属性
问题描述
任何人都可以帮助我解决以下问题吗?在下面的 Gosu 代码中,如何在查询结果中包含地址表中的城市信息(无需翻转表格 - 从地址表开始)?地址表有一个指向用户表的外键,反之则没有外键。行查询可以做到吗?非常感谢
uses gw.api.database.Query
// -- query the User entity --
var queryUser = Query.make(User)
// -- select only User instances who last updated addresses in the city of Chicago --
var tableAddress = queryUser.join(Address, "UpdateUser")
tableAddress.compare("City", Equals, "Chicago")
// -- fetch the User instances with a for loop and print them --
var result = queryUser.select()
for (user in result) {
print (user.DisplayName)
}
解决方案
既然 Address 有用户 FK 为什么不扭转局面呢?
uses gw.api.database.Query
// -- query the Address entity --
var queryAddress = Query.make(Address)
queryAddress.compare("City", Equals, "Chicago")
// -- select only User instances who last updated addresses in the city of Chicago --
var tableUser = queryAddress.join(Address#UpdateUser)
// -- fetch the Addresses instances with a for loop and print them --
var result = tableUser.select()
for (address in result) {
print(address.City?.DisplayName)
print(address.UpdateUser?.DisplayName)
}
推荐阅读
- c - GTK3.0中如何使用gstreamer同时播放视频和音频
- django - 阻止 Django 在 admin 中自动填充多字段
- android - Android Studio 在 hello world 示例中使用 firebase 数据库崩溃
- java - 替换 switch 语句 Java
- python - Selenium Python 帮助获取表单元素
- c++ - Google Test 中测试类的构造函数
- laravel - Laravel MustVerifyEmail 不存在?
- sdn - 如何将数据包转发到 OpenDaylight 控制器
- c# - SendInput 鼠标点击 X/Y
- c# - Oauth token accessing