クエリに追加するパラメータがあります。joinToです。
ここには、ヘッダーファイルのエントリがあります。 SWIFT、2つのテーブルを結合(従業員&ログイン)で
/**
* 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")
明らかに、クラスが実行時に変更することはできませんので、何を記述していることは関係して行うことがはるかにですが、あなたは、joinedResults
をDictionaryオブジェクトに結果を見つけ、Iあなたはここで多くの例に1を見てお勧め:
Relating two objects in DBAccess
だからあなたの特定のケースでは、あなたはPostクラスに次のメソッドを追加します。
func media -> DBResultSet {
return Media.query().whereWithFormat("post_id = %@", withParameters: [self.post_id]).fetch()
}
これは、メディアテーブルから結果を検索して返します。
上記のクラスの説明を使用して、私の答えに具体的な例を追加しました。 –