Hi,
just a question / issue I came across when calling to_yaml on an
object which defines an association and called a method on this
association before the to_yaml. E.g. assume the following classes:
class Partner < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
def some_function
end
end
if you have an instance of partner and you call:
partner.users.some_function
followed by:
partner.to_yaml
it will load and dump all associated user objects since once you
called partner.users.some_function the @users instance variable exists
in partner. Now to_yaml_properties just iterates over all instance
variables and calls them via: instance_variable_get( m ) which in this
case returns the association_proxy which will cause it to load all
users associated with partner. This causes some trouble when a partner
has a lot of users.
To prevent this I think it may be a good idea to define
to_yaml_properties on ActiveRecord::Base and reject instance variables
which are association proxies. This could naively be archived by this:
def to_yaml_properties
instance_variables.reject { |i| instance_variable_get
(i).respond_to?(:proxy_owner) }.sort
end
Thoughts?