我有2张桌子tblAlbum
和tblProduction
,相册与tblProduction
有关系。
(album_title,album_id,制作(ParseRelation的种类),...)
我想写一个查询来获取包含所有制作键的专辑?
像这样(album_title,album_id,production_name,production_title,...)
注意 - 我正在使用Parse PHP SDK。
答案 0 :(得分:0)
我不确定您是否production
设置为指针或关系,但我会在此详细说明。< / p>
作为指针(1-1),您只需像这样调整查询。
$query = new ParseQuery('Album');
// include the nested object under 'production'
$query->includeKey('production');
// get albums with Production set under 'production'
$albums = $query->find();
作为关系(1-many),您需要进行单独的查询以获取所有关联的production
个对象。
$relation = $albums->getRelation('production'); // can add Production as the class name as 2nd arg if you have issues
$relationQuery = $relation->getQuery();
// get all Production objects
$productions = $relationQuery->find();
如果您不断为每个Album
进行此关系查询,则可以将开销降低到大约2个查询。只需在Production
中添加指针即可返回其父Album
,并使用ParseQuery::orQueries
将所有您的关系查询加入一个方便的查询中。
// get albums
$query = new ParseQuery('Album');
$albums = $query->find();
// get each relation query for each album
$queries = [];
foreach($albums as $album) {
$relation = $album->getRelation('production', 'Production');
$queries[] = $relation->getQuery();
}
// combine your relation queries
$query = ParseQuery::orQueries($queries);
// include the parent 'album' pointer so we can
// sort which objects belong where
$query->includeKeys('album');
// get these productions
$productions = $query->find();
您也可以使用matchesKeyInQuery
执行某些操作,但我建议您阅读docs以获取有关详细信息。