Tuesday, February 22, 2011

[Rails] has many to one query

-- MODELS --
Model User
has_many :profs
has_many :skills, :through => :prof

Model Prof
belongs_to :user # user_id
belongs_to :skill # skill_id

Model Skill
has_many :profs

-- CONTROLLER --

searched_skills = [2,18,6] # comes from params[:search_skills]
I need to find @users who having ALL of searched skills.
current code:
@users = User.paginate :conditions => ["profs.skill_id IN (?)",
searched_skills], :include => :profs, :page => page
does not help (since it use OR). It returns all users who having at
least one of searched_skills.
I need this thing in one query that return @users paginated array
(will_paginate)

im late night 4 hours work, plz dont judge me ^_^

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate