ruby on rails - How to scope a join table? -


i'm using filterrific gem, , need scope following.

i have 3 tables. , scope user model , returns university names.that user belongs through colleges. colleges join table here. models below (rails 4.2):

    class user < activerecord::base      has_many :colleges      has_many :universities, :through => colleges       # current scope not working @      scope :user_university, -> (user_university){joins(colleges: [ {university: :name}]).where("universities.name = ? ", user_university)}     end      class colleges < activerecord::base      belongs_to :user      belongs_to :university     end      class university < activerecord::base      has_many :colleges      has_many :users, :through => colleges     end 

i keep getting errors , i'm unsure how scope model through join table.

let try this:

scope :user_university, -> (university_name) {   joins(colleges: :university).where(universities: {name: university_name}) } 

i rename parameter user_university university_name btw, user_university kind of confusing!


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -