-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subclass misses association defined on parent #20678
Comments
To anyone that is going to work on this, I think this is very similar to #18926. |
I guess the cause of this issue would be that Post._reflections['comments'] =>
#<ActiveRecord::Reflection::HasManyReflection:0x007fb24bb55b08 @name=:comments, @scope=nil, @options={}, @active_record=Post(id: integer), @klass=nil, @plural_name="comments", @automatic_inverse_of=nil, @type=nil, @foreign_type="comments_type", @constructable=true, @association_scope_cache={}, @scope_lock=#<Mutex:0x007fb24bb7df18>>
FancyPost._reflections['comments'] =>
nil My workaround for this issue is shown below. https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L153 def association(name) #:nodoc:
association = association_instance_get(name)
if association.nil?
reflection = self.class._reflect_on_association(name)
# if reflection is nil, try to get the parent class' reflection
klass = self.class.superclass
while reflection.nil? && klass.respond_to?(:_reflect_on_association)
reflection = klass._reflect_on_association(name)
klass = klass.superclass
end
unless reflection
raise AssociationNotFoundError.new(self, name)
end
association = reflection.association_class.new(self, reflection)
association_instance_set(name, association)
end
association
end |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
Just ran into this issue when trying to delete a record which is a subclass. Above workaround mitigates the issue.
|
Opened #24719. |
related to #6944 |
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 <joenio@colivre.coop.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
related to #21908 |
- Fixes rails#20678 (Subclass misses association defined on parent) [Jon Moss, Bráulio Bhavamitra]
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 <joenio@colivre.coop.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Fixes ActiveRecord relations for descendants Temporary fix, waiting for original fix to be merged. Original author: Jon Moss Merge Request: rails/rails#24719 Issue: rails/rails#20678 See merge request !914
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 <joenio@colivre.coop.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> (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 <joenio@colivre.coop.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
This is a common `class_attribute` implementation issue (e.g. rails#39467, rails#39468, rails#38871). For now, we should take care of the change propagation by themselves if we want to ensure the propagation after the `class_attribute` are accessed in subclasses. Fixes rails#20678.
The problem was 'Association named 'project_custom_fields' was not found on ProjectType'. This error occurs although the parent class of ProjectType, what is Project, has the association above defined. This problem is related to Rails rails/rails#20678 (comment). Implements #1474
If an association is defined on the superclass after a subclass has been given an association of its own, the subclass will have the association methods present, but calling them will raise AssociationNotFoundError.
https://gist.github.com/matthewd/8b88b7356d4076fe6a10
The text was updated successfully, but these errors were encountered: