Hi all, I am having trouble trying to use reflect_on_association method with given the simplified model: class Order < ActiveRecord::Base belongs_to :contractor, :class_name => "BusinessUnit" end I expected the reflect_on_association method to return associated_foreign_key "contractor_id" but it returns "business_unit_id": ruby-1.9.2-p0 > Order.reflect_on_association(:contractor).association_foreign_key => "business_unit_id" do I miss something? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bojan Mihelac wrote:> Hi all, I am having trouble trying to use reflect_on_association > method with given the simplified model: > > class Order < ActiveRecord::Base > belongs_to :contractor, :class_name => "BusinessUnit" > end > > I expected the reflect_on_association method to return > associated_foreign_key "contractor_id" but it returns > "business_unit_id": > > ruby-1.9.2-p0 > > Order.reflect_on_association(:contractor).association_foreign_key > => "business_unit_id" > > do I miss something?What version of Rails are you using? At least in the 2.2.2 docs I''m looking at right now, :association_foreign_key isn''t a valid option for belongs_to (it''s only for habtm), so I''m not surprised that you''re getting strange results. Try foreign_key. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 9:17 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Bojan Mihelac wrote: > > Hi all, I am having trouble trying to use reflect_on_association > > method with given the simplified model: > > > class Order < ActiveRecord::Base > > belongs_to :contractor, :class_name => "BusinessUnit" > > end > > > I expected the reflect_on_association method to return > > associated_foreign_key "contractor_id" but it returns > > "business_unit_id": > > > ruby-1.9.2-p0 > > > Order.reflect_on_association(:contractor).association_foreign_key > > => "business_unit_id" > > > do I miss something? > > What version of Rails are you using? At least in the 2.2.2 docs I''m > looking at right now, :association_foreign_key isn''t a valid option for > belongs_to (it''s only for habtm), so I''m not surprised that you''re > getting strange results. Try foreign_key. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted viahttp://www.ruby-forum.com/.I found it, should use primary_key_name: ruby-1.9.2-p0 > Order.reflect_on_association(:contractor).primary_key_name => "contractor_id" I thought at first that I would get it with foreign_key but it that method doesnt exists in ActiveRecord::Reflection::AssociationReflection -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.