This project is archived and is in readonly mode.
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
-
Manfred Stienstra January 11th, 2009 @ 11:41 AM
Nice, I think we've had this refactoring floating around for around 6 months now.
+1 Applies and tests run.
-
Eloy Duran January 11th, 2009 @ 11:48 AM
@manfred Yup, indeed we did :) Right now I'm tearing the big patch it was part of apart, that should make it in easier.
-
Michael Koziarski January 12th, 2009 @ 05:20 AM
- Milestone cleared.
- Assigned user set to Michael Koziarski
This actually subtly changes the semantics as it doesn't do a test for instance_variable_defined?(...)
However, that doesn't actually seem to matter...
-
Michael Koziarski February 1st, 2009 @ 02:07 AM
- Milestone set to 2.x
This doesn't apply cleanly any more as someone went and added heaps of code to associations.rb for the nested params stuff :)
-
Eloy Duran February 1st, 2009 @ 01:09 PM
This was applied in commit ec8f04584479aff895b0b511a7ba1e9d33f84067. Please close the ticket.
-
Michael Koziarski February 1st, 2009 @ 09:43 PM
- State changed from new to resolved
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
Tags
Referenced by
- 1202 Add attributes writer method for an association. Accessor methods for association instances. #1728
- 1202 Add attributes writer method for an association. Added the association accessor methods association_instan...