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 = "@#{}"

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

# 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(
  # ...

# and for writing
association_instance_set(, 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=""></a>

People watching this ticket


Referenced by