Reddirt
Reddirt

Reputation: 5953

Ruby on Rails where statement

I have a worequest table that belongs to contact table. The contact table belongs to the user table.

I'm listing the worequest records, but want to limit it to the records for the current user.

This doesn't work:

<% Worequest.where(:contact_id.contact.user_id => current_user.id).each do |worequest| %>

What would?

Upvotes: 0

Views: 154

Answers (1)

lest
lest

Reputation: 8100

I would recommend using through association, e.g.:

class Contact < ActiveRecord::Base
  has_many :worequests
end

class User < ActiveRecord::Base
  has_many :contacts
  has_many :worequests, :through => :contacts
end

And then use the following:

current_user.worequests

Upvotes: 1

Related Questions