This project is archived and is in readonly mode.

#1728 ✓resolved
Eloy Duran

Accessor methods for association instances.

Reported by Eloy Duran | January 11th, 2009 @ 01:29 AM | in 2.x

Currently the active_record/associations.rb contains code like the following:


ivar = "@#{reflection.name}"

# for reading
association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
if association.respond_to?(:loaded?)
  # ...
end

# and for writing
instance_variable_set(ivar, association)

This patch cleans this up by providing a association_instance_get and a association_instance_set method, which provide the same functionality as described above.


# for reading
if association = association_instance_get(reflection.name)
  # ...
end

# and for writing
association_instance_set(reflection.name, association)

As you can see, it's the same minus the instance_variable_defined? part. Tests have shown that this call is not needed. Please provide feedback if it it needed for a unknown reason.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages