Hi! I have two classes, ''node'' and ''way'', linked by ''way_node''. It''s a fairly straightforward relationship: node: has_many :way_nodes has_many :ways, :through => :way_nodes way: has_many :way_nodes, :foreign_key => ''id'', :order => ''sequence_id'' has_many :nodes, :through => :way_nodes, :order => ''sequence_id'' way_node: belongs_to :node belongs_to :way, :foreign_key => :id This typically results in queries like: SELECT [blah] FROM nodes LEFT OUTER JOIN way_nodes ON (nodes.id = way_nodes.node_id) LEFT OUTER JOIN ways ON (ways.id = way_nodes.id) However, for one single query in the app, I''d like to join via a different table. In other words: SELECT [blah] FROM nodes LEFT OUTER JOIN new_table ON (nodes.id = new_table.node_id) LEFT OUTER JOIN ways ON (ways.id = new_table.id) Is there any way of doing this? I''d wondered about the :joins option in ''find'', but it only adds additional joins, rather than replacing the existing ones. Thanks for any help! cheers Richard -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
How about has_many :ways2, :class_name => "Way", :through => :new_ways You''d need another model for new_ways and appropriate associations to way. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks - after another suggestion I ended up doing something very similar: node.rb: has_many :old_way_nodes has_many :ways_via_history, :class_name=> "Way", :through => :old_way_nodes, :source => :way old_way_node.rb: belongs_to :way, :foreign_key=> :id The :source meant I didn''t even have to set up a new model. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---