Kad Kerforn
2007-May-12 08:49 UTC
REST routing issue w self-referential resource join model..
I have a ''user'' resource w route => map.resources :users user model is defined as self-referential class User < ActiveRecord::Base has_many :relationships_as_befriender, :foreign_key => ''befriender_id'', :class_name => ''User'' has_many :relationships_as_friend, :foreign_key => ''friend_id'', :class_name => ''User'' has_many :friends, :through => :relationships_as_friend has_many :befrienders, :through => :relationships_as_befriender .... I created the nested ''relationship'' resource class Relationship < ActiveRecord::Base set_primary_key :relation_id belongs_to :befriender, :foreign_key => "befriender_id", :class_name => "User" belongs_to :friend, :foreign_key => "friend_id", :class_name => "User" ... if I had a one-to-many , I know that the route should be created like that... map.resources :users do |users| users.resources :relationships end but if I require /users/1/relationships , it will use the user_id as a foreign_key... and fail relationship_url failed to generate from {:action=>"show", :user_id=>"1", :controller=>"relationships"}, expected: {:action=>"show", :controller=>"relationships"}, diff: {:user_id=>"1"} how should I write teh routes ? (tips or links to solution accepted..... ;-)) kad -- 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 -~----------~----~----~----~------~----~------~--~---