Repository navigation
Conversation
|
Take my money! xD |
|
r? @sgrif |
|
Can you add a test which eager loads as well? |
There was a problem hiding this comment.
This sounds like something a test is relying on -- otherwise, why would it have been specifically set?
There was a problem hiding this comment.
It looks like this has been around since roughly 2008 (centralized DB schema + git history gets a bit sketchy after that, looks like could have been around since 2006), but no tests break when I remove this, so... 😬
There was a problem hiding this comment.
My worry is that a test is assuming it's there, for the purposes of proving that something works with a null: false column. So removing it wouldn't cause a test to fail, but may cause a test to stop testing what it previously was.
There was a problem hiding this comment.
How would you recommend that I check to make sure this isn't happening? 😬 Worst come to worst, I can add another model, and start fresh.
|
updated @sgrif |
There was a problem hiding this comment.
At a glance, this sounds like too high-level of a place to do this: aren't other places expecting _reflect_on_association to have a complete view of the available associations?
There was a problem hiding this comment.
Should I push this down the stack to _reflect_on_association? The problem there, is that since this method is included via an AS::Concern, it doesn't know about the current class its dealing with, and thus wouldn't be able to construct the superclass tree, etc.
There was a problem hiding this comment.
Yes that is probably the level to push this to, but we should have tests
for all the visible effects of this regardless of where it's implemented
On Wed, May 11, 2016, 10:33 PM Jon Moss [email protected] wrote:
In activerecord/lib/active_record/associations.rb
#24719 (comment):@@ -229,7 +229,16 @@ def association(name) #:nodoc:
association = association_instance_get(name)if association.nil?
unless reflection = self.class._reflect_on_association(name)reflection = self.class._reflect_on_association(name)Should I push this down the stack to _reflect_on_association? The problem
there, is that since this method is included via an AS::Concern, it
doesn't know about the current class its dealing with, and thus wouldn't be
able to construct the superclass tree, etc.—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/rails/rails/pull/24719/files/e22146a58b93d4a5ea53ef481387738f58bb1fd5#r62957427
|
It's worth noting the model knows which classes have inherited from it. So instead of having the subclass hold an almost-but-not-quite-complete list of associations but then still fall back to the parent, maybe we should walk the children at the time the new association is defined. Otherwise, if we're going to fall back to the parent anyway, maybe the subclass should only be tracking its own associations, and never those defined further up. |
Temporary fix, waiting for original fix to be merged. Original author: Jon Moss Merge Request: rails/rails#24719 Issue: rails/rails#20678 Signed-off-by: Joenio Costa <[email protected]> Signed-off-by: Marcos Ronaldo <[email protected]> Signed-off-by: Tallys Martins <[email protected]>
|
@matthewd I think if we rely on the parent class to manage its subclasses, associations could get out of date. An example of this could be that in Not sure if this is a real thing we need to be considering -- if not, I'm happy to redo the implementation if that's a better course (superclass going through and adding associations to its subclasses, when defined) |
|
After reviewing the associations code some more, totally on same page as @matthewd -- parents should take responsibility for defining associations on their children. Updated code to reflect this. |
There was a problem hiding this comment.
If anyone has a way of making ar.descendants << ar look prettier, I'm all for it. All we're doing here is creating an array with all of the classes we're going to be adding the new reflection to (ar's descendants and ar itself), to try and stay DRY. ☔
There was a problem hiding this comment.
Don't know how to improve on ar.descendants << ar, but I do have a 😊 reaaally 😊 small nitpick: record var name is usually used for AR instances, maybe switch record -> ar_class?
|
please check the duplicate at #21908 |
|
@brauliobo Sorry about that, sometimes it's hard to keep things like that from slipping through the cracks. I'm working to get the backlog down so that doesn't happen anymore. @maclover7 Can you credit him in the commit as well after you squash & rebase? |
|
no problem @sgrif, thanks for the credit note. btw, I think the best fix would be to add an option to |
|
I don't think this is something we can generalize as it only applies to On Mon, May 16, 2016, 12:15 PM Bráulio Bhavamitra [email protected]
|
- Fixes #20678 (Subclass misses association defined on parent) [Jon Moss, Bráulio Bhavamitra]
|
👍 updated PR |
Temporary fix, waiting for original fix to be merged. Original author: Jon Moss Merge Request: rails/rails#24719 Issue: rails/rails#20678 Signed-off-by: Joenio Costa <[email protected]> Signed-off-by: Marcos Ronaldo <[email protected]> Signed-off-by: Tallys Martins <[email protected]> (cherry picked from commit 3b60e7c)
Temporary fix, waiting for original fix to be merged. Original author: Jon Moss Merge Request: rails/rails#24719 Issue: rails/rails#20678 Signed-off-by: Joenio Costa <[email protected]> Signed-off-by: Marcos Ronaldo <[email protected]> Signed-off-by: Tallys Martins <[email protected]>
| self.table_name = 'pirates' | ||
| end | ||
|
|
||
| class SpecialPirate2 < SpecialPirate1 |
There was a problem hiding this comment.
This subclass needs an association of some kind in order to reproduce the issue properly: https://gist.github.com/matthewd/8b88b7356d4076fe6a10#file-gistfile1-rb-L20.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
|
I'm experiencing this issue after upgrading to rails 7 |
`add_reflection` writes a new frozen `_reflections` hash to the class that defines the association. A subclass that had already defined an association of its own holds its own copy, so an association added to the parent afterwards never reaches it: the generated reader exists on the subclass, but `association` can't find the reflection and raises `AssociationNotFoundError`. Subclasses that only inherit the hash can also keep a stale `normalized_reflections` cache. When a reflection is added, walk the class's descendants, clear their caches, and add it to each one that has its own copy, unless that subclass (or a class between it and the parent) defines the same name. This follows the direction from the review of #24719. Fix #20678
I can add a test to check on
SpecialUser._reflections['comments'], but I wasn't sure if that was digging too deep into Active Record internals 😬