Silverstripe按父页面属性筛选

时间:2014-01-17 05:08:51

标签: silverstripe

通过dataobject orm查询数据库时,如何通过页面父项的属性过滤记录?

所以我想到的是:

$facilities_by_keyword = Facility::get()->filter('Parent.tags:partialmatch', $tag);

1 个答案:

答案 0 :(得分:1)

您可以先获取所有父页面。然后获取作为任何这些父页面的子项的Facility页面:

$parentPages = Page::get()->filter('Parent.tags:partialmatch', $tag);
$parentIDs = $parentPages->getIDList();
$facilities_by_keyword = Facility::get()->where('ParentID IN (' . implode(',', $parentIDs) . ')');