在A.find(:all, :include => [:b])这个写法里,如果有两层关联的话,应该怎么写啊?
关系貌似很复杂,我整理了一下:a b c三个模型,我们要查找“a里面,c的xxx字段满足条件x的记录”,而abc三者的关系是:
[list]
[*]a has_many bs, b belongs_to c 这样的格式,我知道应该这样:
A.find(:all, :conditions => ["cs.xxx like ?","%x%"], :include => [{:bs => :c}])
[*]a belongs_to b, b belongs_to c 这样的格式,这样:
A.find(:all, :conditions => ["cs.xxx like ?","%x%"], :include => [{:b => :c}])
[*][color=red]a belongs_to b, b has_many cs[/color]
[*][color=red]a has_many bs, b has_many cs[/color]
[/list]
红色的这两种应该怎么写呢?