我有3张桌子:
schools{id, name, desc, adress}
reviews{id, content, rating, school_id, user_id} # user_id & schoold_id is foregin keys
users{id, name, city}
如何编写rails范围,连接所有3个表并获取列
schools.name
,reviews.content
和reviews.rating
,users.name
我正在使用rails 3.2
答案 0 :(得分:1)
scope :mashup, joins(:school, :user).select("content, rating, schools.name as sname, users.name as uname")
您可以了解更多here