lib/cancan/model_adapters/active_record_adapter.rb
# When belongs_to parent_id is a condition for a model,
# we want to check the parent when testing ability for a hash {parent => model}
When belongs_to parent_id is a condition for a model,
we want to check the parent when testing ability for a hash {parent => model}
When belongs_to parent_id is a condition for a model we want to check the parent when testing ability for a hash { parent = > model }
def parent_child_conditions(parent, child, all_conditions)
          child_class = child.is_a?(Class) ? child : child.class
          foreign_key = child_class.reflect_on_all_associations(:belongs_to).find do |association|
                          association.klass == parent.class
                        end&.foreign_key&.to_sym
          foreign_key.nil? ? nil : all_conditions[foreign_key]
        end
def parent_child_conditions ( parent , child , all_conditions ) child_class = child . is_a? ( Class ) ? child : child . class foreign_key = child_class . reflect_on_all_associations ( :belongs_to ) . find do | association | association . klass == parent . class end &. foreign_key &. to_sym foreign_key . nil? ? nil : all_conditions [ foreign_key ] end
When belongs_to parent_id is a condition for a model,
we want to check the parent when testing ability for a hash {parent => model}
When belongs_to parent_id is a condition for a model we want to check the parent when testing ability for a hash { parent = > model }
parent
<not_specific>
child
<not_specific>
all_conditions
<not_specific>