Class: AssociationScope::Scope::ThroughReflection
- Inherits:
-
AssociationScope::Scope
- Object
- AssociationScope::Scope
- AssociationScope::Scope::ThroughReflection
- Defined in:
- lib/association_scope/scope/through_reflection.rb
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/through_reflection.rb', line 6 def apply association = @association class_name = reflection_details.[:class_name]&.constantize || association.singularize.camelize.constantize first_join = inverse_reflection(class_name)&.&.fetch(:through, nil) || inverse_reflection(class_name)&.&.fetch(:source, nil) second_join = compute_second_join class_name raise AssociationMissingError.new missing_in: class_name, association: inverse unless inverse_reflection(class_name) model.class_eval <<-RUBY, __FILE__, __LINE__ + 1 scope association.pluralize, -> do class_name .joins(first_join => second_join) .distinct end RUBY end |