This project is archived and is in readonly mode.
Add inverse polymorphic association support
-
Eloy Duran
- Assigned user set to Michael Koziarski
I’m wondering, why do you need to fix all these other tests? Eg:
- m = Man.find(:first, :include => :interests) + m = Man.find(:first, :conditions => {:name => 'Gordon'}, :include => :interests)Is it simply because you want to use a specific fixture? Or does the patch somehow change existing functionality elsewhere?
-
Eloy Duran
- Milestone set to 2.3.6
-
Murray Steele
George's above patch is good. However, attached is a new patch that:
a) includes George's patch tweaked to apply cleanly on top of my extra tests patch for #3513
b) adds another test for checking that polymorphic belongs_to associations can be assigned via direct accessor not just the .replace method
c) provides a slightly more robust we_can_set_the_inverse_on_this? method for polymorphic belongs_to associations. -
Murray Steele
One concern I have is that a polymorphic belongs_to using :inverse_of will never throw an InverseOfAssociationNotFoundError if the supplied :inverse_of doesn't actually match. This breaks symmetry with the other :inverse_of associations, but I'm not sure exactly what the correct place to throw such an error might be. We can't throw it during class definition, as the :inverse_of depends on the class of the polymorphic instance, but throwing it during assignment (or load) seems a tad late in the process.
Note, I don't think this should hold up this patch though.
-
Murray Steele
In response to Eloy's comments on IRC, the attached patch now makes polymorphic_inverse_of on Reflection throw an InverseOfAssociationNotFoundError if the supplied associated_class doesn't have the correct association on it.
There are 2 tests for this that appear to test the same thing, but I think they are subtly different:
- test that it throws if the association is broken (e.g. nothing
has the correct inverse - it would throw regardless of what we try
to assign)
- test that it throws if the association is fine, but the instance being assigned doesn't have the correct association (e.g. we can assign some things, but not others)
- test that it throws if the association is broken (e.g. nothing
has the correct inverse - it would throw regardless of what we try
to assign)
-
Eloy Duran
@Murray: I applied your last patch to 2-3-stable. I hope you don't mind I removed a few lines of code. Namely, returning ‘nil’ from an ‘else’ clause isn't necessary.
-
Repository
- State changed from verified to resolved
(from [cca75ca23f7c2a144104e1d96378e7afd9fdd189]) Add inverse polymorphic association support. [#3520 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/cca75ca23f7c2a144104e1d96378e7... -
Repository
(from [603b28c84c1ba1d013247fee450d82f015aaefb3]) Provide a slightly more robust we_can_set_the_inverse_on_this? method for polymorphic belongs_to associations. [#3520 state:resolved]
Also add a new test for polymorphic belongs_to that test direct accessor assignment, not just .replace assignment.
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/603b28c84c1ba1d013247fee450d82... -
Repository
(from [3470b306bb22df0394025f4dcf3915eb1166ac23]) Make polymorphic_inverse_of in Reflection throw an InverseOfAssociationNotFoundError if the supplied class doesn't have the appropriate association. [#3520 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/3470b306bb22df0394025f4dcf3915... -
Repository
(from [81ca0cf2b074f4b868a84c427ef155607a956119]) Add inverse polymorphic association support. [#3520 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/81ca0cf2b074f4b868a84c427ef155... -
Repository
(from [6a74ee7f4deea4a44520d3fcc9120e0bb848823f]) Provide a slightly more robust we_can_set_the_inverse_on_this? method for polymorphic belongs_to associations. [#3520 state:resolved]
Also add a new test for polymorphic belongs_to that test direct accessor assignment, not just .replace assignment.
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/6a74ee7f4deea4a44520d3fcc9120e... -
Repository
(from [ff508640e28914da2b546f6a8c9f215bab201b61]) Make polymorphic_inverse_of in Reflection throw an InverseOfAssociationNotFoundError if the supplied class doesn't have the appropriate association. [#3520 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/ff508640e28914da2b546f6a8c9f21...
