def add_helper_methods(klass, attribute)
association = self
klass.class_eval do
define_method("#{attribute}_id") do
prefix_options["#{attribute}_id".intern]
super()
end
define_method("#{attribute}_id=") do |value|
prefix_options["#{attribute}_id".intern] = value
super(value)
end
define_method(attribute) do
unless instance_variable_get("@#{attribute}")
object = association.resolve_relationship(self)
instance_variable_set("@#{attribute}", object)
end
instance_variable_get("@#{attribute}")
end
end
associated_class.belongs_to_associations.each do |parent_attribute|
parent_attribute.add_helper_methods(klass, parent_attribute.attribute)
end
end