as join_table bs ---------- --------------- -------- id <------. id ,----> id name `---*> a_id ,'' name b_id <--'' holy_graal 1) I''m trying to find the most clean and elegent way of accessing holy_graal given an instance of a and b. I refuse to believe the only way is to do a cold search like Join_table.find (:first, :conditions => insert a.id and b.id here) (In my case, join_table can only contain one combination of a_id and b_id.) 2) Furthermore, I''ve read I shouldn''t use the << operator for storing when in has_many :through relations. I''ve also read I shouldn''t use push_with_attributes. So what should I use? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
One more question: I read I should be able to do... a.holy_graal ...if I just add the line... has_many :bs, :through => :join_table, :select => "join_table.holy_graal, b.*" ...to the class declaration for A. I can''t get this working though. Is there anything more to it I might be missing? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vincent wrote:> One more question: I read I should be able to do... > a.holy_graal > ...if I just add the line... > has_many :bs, :through => :join_table, :select => > "join_table.holy_graal, b.*" > ...to the class declaration for A. > > I can''t get this working though. Is there anything more to it I might be > missing?You don''t need the :select option. the :through option takes care of all that for you. I have a lot of examples on my site. Check out this one: http://blog.hasmanythrough.com/articles/2006/08/19/magic-join-model-creation -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Great reading Josh, bookmarked it as well. That takes care of my q#2. In my dream language (which has yet to be invented), the answer to the question "most elegant way to connect two instances via a join_table with an attribute" would be: a << attribute >> b or a << attribute1, attribute2 >> b Is there anyway I can override the << operator so that I can associate instance a with b with a join table attribute? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---