1

I get a metawhere join dependency error with the following:

@companies_user = Company.joins(:contact).where(:contact => {:user_id => current_user.id}).uniq

Company has_many contacts

In other words, every Contact has a method company_id

I want to show those companies (only one) where the contacts have a user_id equal to that of the user doing the search.

Satchel
  • 16,414
  • 23
  • 106
  • 192

2 Answers2

0

Why not doing it this way?

current_user.contact.companies

Then you can use .limit to only fetch one...

davidb
  • 8,884
  • 4
  • 36
  • 72
0

Well, if your company has many contacts then you should include contacts not contact

@companies_user = Company.joins(:contacts).where(:contacts => {:user_id => current_user.id}).uniq
dombesz
  • 7,890
  • 5
  • 38
  • 47