turkan
2010-Nov-20 01:12 UTC
Bug when serializing to_xml when :foreign_key is named like association
Think of the following models: class User < ActiveRecord::Base has_many :created_entities, :class_name => "Entity", :foreign_key => "created_by" end class Entity < ActiveRecord::Base belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" end There is also a created_by integer field in the Entity migration. Everything seems to work fine with these model (fetching the association and so on), but when I try to serialize Entity.to_xml :include => :created_by (or include something other the model has as association) it fails (NoMethodError: undefined method `macro'' for nil:NilClass). For full trace see: http://stackoverflow.com/questions/4217923/nomethoderror-when-serializing-to-xml But as soon as I rename the association in the Entity model to: belongs_to :creator, :class_name => "User", :foreign_key => "created_by" the serialization to_xml start to work again. Im using Rails 3.0.1. Can someone reproduce that? -- 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.
turkan
2010-Nov-20 01:26 UTC
Re: Bug when serializing to_xml when :foreign_key is named like association
Guess what ... solved in Rails 3.0.3 :-) On Nov 20, 2:12 am, turkan <kai.schl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Think of the following models: > > class User < ActiveRecord::Base > has_many :created_entities, :class_name => "Entity", :foreign_key => > "created_by" > end > > class Entity < ActiveRecord::Base > belongs_to :created_by, :class_name => "User", :foreign_key => > "created_by" > end > > There is also a created_by integer field in the Entity migration. > Everything seems to work fine with these model (fetching the > association and so on), but when I try to serialize > Entity.to_xml :include => :created_by (or include something other the > model has as association) it fails (NoMethodError: undefined method > `macro'' for nil:NilClass). > For full trace see:http://stackoverflow.com/questions/4217923/nomethoderror-when-seriali... > > But as soon as I rename the association in the Entity model to: > belongs_to :creator, :class_name => "User", :foreign_key => > "created_by" > the serialization to_xml start to work again. > > Im using Rails 3.0.1. Can someone reproduce that?-- 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.
Frederick Cheung
2010-Nov-20 04:04 UTC
Re: Bug when serializing to_xml when :foreign_key is named like association
On Nov 20, 1:26 am, turkan <kai.schl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Guess what ... solved in Rails 3.0.3 :-) >I''d say you''re skating on thin ice: what''s some_entity.created_by supposed to return: the foreign_key or an instance of User? Fred> On Nov 20, 2:12 am, turkan <kai.schl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Think of the following models: > > > class User < ActiveRecord::Base > > has_many :created_entities, :class_name => "Entity", :foreign_key => > > "created_by" > > end > > > class Entity < ActiveRecord::Base > > belongs_to :created_by, :class_name => "User", :foreign_key => > > "created_by" > > end > > > There is also a created_by integer field in the Entity migration. > > Everything seems to work fine with these model (fetching the > > association and so on), but when I try to serialize > > Entity.to_xml :include => :created_by (or include something other the > > model has as association) it fails (NoMethodError: undefined method > > `macro'' for nil:NilClass). > > For full trace see:http://stackoverflow.com/questions/4217923/nomethoderror-when-seriali... > > > But as soon as I rename the association in the Entity model to: > > belongs_to :creator, :class_name => "User", :foreign_key => > > "created_by" > > the serialization to_xml start to work again. > > > Im using Rails 3.0.1. Can someone reproduce that?-- 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.