访问has_one关系的字段Silvestripe

时间:2016-06-10 13:43:03

标签: silverstripe

我有一个与Teamhas_one关系的DataObject Member。我想使用ORM搜索Team,但能够按相关Member表的一个字段的值过滤记录。为了更清楚,我可以用SQL实现相同的结果:

SELECT * FROM Member 
LEFT JOIN Team ON Team.MemberID=Member.ID 
  WHERE Member.CityID=142 
  AND Team.Target='Boy'
  AND Team.GenreID=51 
  AND Team.Fyr <= 9 
  AND Team.Tyr >= 9

好的,我明白了。答案是:

$teams= Team::get()->filter(array('Member.CityID:ExactMatch' => $var));

以后只需过滤$teams

0 个答案:

没有答案