This project is archived and is in readonly mode.
has_one :through errors
Reported by Adam Milligan | August 25th, 2008 @ 12:47 AM | in 2.x
This patch resolves two small errors in has_one :through associations:
1) An unassigned has_one :through association should return nil when referenced. Instead, it returns an empty array. This is due to the call to #reset_target! on AssociationCollection, which is the most derived class that defines that method in the inheritance hierarchy for HasOneThroughAssociation.
2) Assigning to a has_one :through association does not correctly assign to the target of the association. This is due to the way the target gets set in the attribute writer method. The attribute writer creates the join association, then delegates to the attribute reader, with an explicit reload, to recreate the has_one :through association and save it on the instance. However, after calling the attribute reader, the attribute writer overwrites the instance variable with an out of date association object.
This patch includes tests for each of these behaviors, along with fixes.
Comments and changes to this ticket
-
Michael Koziarski August 25th, 2008 @ 09:41 AM
- Assigned user set to Michael Koziarski
Hi there,
There's an awful lot of whitespace changes in this patch which make it a little hard to follow. Are the two changes stand alone?
If so it'd be nice to get seperate changesets for each of them with the whitespace changes either not included, or in a seperate changeset (as they're removing trailing whitespace I'm happy to take them).
-
Adam Milligan August 26th, 2008 @ 05:37 PM
- no changes were found...
-
Adam Milligan August 26th, 2008 @ 05:37 PM
Sorry, my editor removed the whitespace automatically. It looked like it was in line with the Rails code standards so I left it in.
Here is a new patch without the whitespace changes.
-
Repository August 27th, 2008 @ 10:25 AM
- State changed from new to committed
(from [9dbde4f5cbd0617ee6cce3e41d41335f9c9ce3fd]) Fix two has_one :through errors
- Set the association target on assignment;
- Reset target to nil on reset, rather than empty array.
Signed-off-by: Michael Koziarski michael@koziarski.com [#895 state:committed] http://github.com/rails/rails/co...
-
Michael Koziarski August 27th, 2008 @ 10:25 AM
No worries, they're definitely the correct format but I try to have whitespace changes on their own to prevent people getting confused by later uses of git blame.
-
Repository August 27th, 2008 @ 10:27 AM
(from [e710902f26a2eed7adb22082067df449b9641d00]) Fix two has_one :through errors
- Set the association target on assignment;
- Reset target to nil on reset, rather than empty array.
Signed-off-by: Michael Koziarski michael@koziarski.com [#895 state:committed] http://github.com/rails/rails/co...
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
- 895 has_one :through errors Signed-off-by: Michael Koziarski michael@koziarski.com [#...
- 895 has_one :through errors Signed-off-by: Michael Koziarski michael@koziarski.com [#...
- 1642 HasOneThroughAssociation should not be a child of HasManyThroughAssociation This inheritance relationship has already caused its shar...
- 1642 HasOneThroughAssociation should not be a child of HasManyThroughAssociation From a more pragmatic point of view, this branching logic...
- 1642 HasOneThroughAssociation should not be a child of HasManyThroughAssociation 3) Please look at activerecord/lib/active_record/associat...