-1
說我有一個協會以下型號:迭代的SQL組由Rails的
House belongs_to User
User has_many House
有沒有一種方法,我可以這樣做使用SQL(不紅寶石GROUP_BY)
House.group(:user).each |houses_grouped_by_user|
#Each of these objects would be a set of houses with the same user id
end
爲什麼你不使用'user.houses'?並通過'User.includes(:houses)'循環 –