Mohammad Sadiq Shaikh
Mohammad Sadiq Shaikh

Reputation: 3200

How to make join of three tables in Rails 3.2

I have three tables as follows

I want all information from the above three tables in one query

i.e. I want to make join of three tables for one common id field

I have the following query which retrives only two table fields

 @details=User.find(:all,:joins => :profile,:select => "*")

How to do it for all three tables ???

Upvotes: 0

Views: 1789

Answers (2)

mld.oscar
mld.oscar

Reputation: 438

This worked for me:

value_variable = 'hello world'
Member.joins(:person => [:workplace => [:business]]).where("businesses.name LIKE :value", value: "%#{value_variable}%")

NOTE: Tested on rails 3.2, 4.x, 5.x

Upvotes: 1

MrTheWalrus
MrTheWalrus

Reputation: 9700

Here's how this query would look:

@details = User.select('*').joins(:profile, :details).all

I'm not convinced this is actually a good way to do anything, but it should work.

Upvotes: 3

Related Questions