Class: AssociationScope::Scope::HasManyReflection
- Inherits:
-
AssociationScope::Scope
- Object
- AssociationScope::Scope
- AssociationScope::Scope::HasManyReflection
- Defined in:
- lib/association_scope/scope/has_many_reflection.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from AssociationScope::Scope
Instance Method Summary collapse
Methods inherited from AssociationScope::Scope
Constructor Details
This class inherits a constructor from AssociationScope::Scope
Instance Method Details
#apply ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/association_scope/scope/has_many_reflection.rb', line 6 def apply class_name = reflection_details.[:class_name]&.constantize || association.singularize.camelize.constantize association = @association.pluralize column_name = reflection_details.[:as] || model.to_s.underscore raise AssociationMissingError.new(missing_in: class_name, association: column_name) unless class_name.reflections.has_key?(column_name.to_s) model.class_eval <<-RUBY, __FILE__, __LINE__ + 1 scope association, -> do class_name .where(column_name => self) .distinct end RUBY end |