您向查询添加了一个参数joinTo。
这是头文件中的条目。
/**
* Used to include "joined" data within the query string, you must use the tablename.columnname syntax within a where statement
*
* @param (Class)joinTo the class you would like to pwrform a SQL JOIN with
* @param (NSString*)leftParameter the property name that you would like to use within the local object to match against the target
* @param (NSString*)targetParameter the property within the class you wish to join with that will be matched with the left parameter.
* @return (DBQuery*) this value can be discarded or used to nest queries together to form clear and concise statements.
*/
- (DBQuery*)joinTo:(Class)joinClass leftParameter:(NSString*)leftParameter targetParameter:(NSString*)targetParameter;
下面是一个快速链接两个表(员工和登录)的示例。
Employee.query().joinTo(Login, leftParameter: "login", targetParameter: "Id")
很明显,类在运行时是不能改变的,所以你在 Dictionary 对象中找到结果,joinedResults
尽管您所描述的更多地与关系有关,但我建议您在此处查看一对多示例:
在 DBAccess 中关联两个对象
因此,在您的特定情况下,您可以将以下方法添加到您的 Post 类中。
func media -> DBResultSet {
return Media.query().whereWithFormat("post_id = %@", withParameters: [self.post_id]).fetch()
}
这将从媒体表中查找并返回结果。