user592638
user592638

Reputation:

Rails scope - how to join 3 tables

I have 3 tables:

schools{id, name, desc, adress}
reviews{id, content, rating, school_id, user_id} # user_id & schoold_id is foregin keys
users{id, name, city}

How do I write a rails scope the joins all 3 tables and grab the column the schools.name , reviews.content and reviews.rating, the users.name

I am using rails 3.2

Upvotes: 3

Views: 2277

Answers (1)

dmoss18
dmoss18

Reputation: 867

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

You can learn more here

Upvotes: 1

Related Questions