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:
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?