我有一个与Team
有has_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