3

我有 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.namereviews.contentreviews.ratingusers.name

我正在使用导轨 3.2

4

1 回答 1

1
scope :mashup, joins(:school, :user).select("content, rating, schools.name as sname, users.name as uname")

你可以在这里了解更多

于 2013-03-01T22:23:31.200 回答