Mister Yu
2007-Aug-11 19:27 UTC
How to access to the attributes of the middle table set up by :through?
Hello all, i have 3 models here: place: ...... #the users who visited the place has_many :visiteds has_many :visitors, :through=>:visiteds, :source=>:user user: ...... #the places this user has visited has_many :visiteds has_many :visited_places, :through=>:visiteds, :source=>:place visited: (id, user_id, place_id, recommended(boolean) ) class Visited < ActiveRecord::Base belongs_to :user belongs_to :place end a user can "been to" a place using: visited = a_place.visiteds.build(:recommended => true) visited.user = a_user visited.save! but how do i access back to the attributes of the middle table? currently, i m doing this: visited current_user.visiteds.find(:first, :conditions=>["place_id = ?" ,placeid]) recommand = visited.recommended but this looks quite stupid, is there any "built-in" way i can do this? Thank you. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---