2013-03-11 66 views

回答

0

如果使用蒙戈你可以試試:

A.where(:b.in => B.where(:flag => true).map(&:id)) 

'b'是A(belongs_to b)中關係的名稱。

1

嘗試

A.joins(:b).where(bs: { flat: true }) 

注意bs在使用時要注意B.

的複數形式
0

U可以使用下面的查詢來獲取所有A的B型的,其標誌設置爲true。

@a = A.bs.where(:flag => true)