lib/hanami/model/associations/has_many.rb in hanami-model-1.1.0.beta3 vs lib/hanami/model/associations/has_many.rb in hanami-model-1.1.0.rc1

- old
+ new

@@ -5,11 +5,11 @@ module Associations # One-To-Many association # # @since 0.7.0 # @api private - class HasMany + class HasMany # rubocop:disable Metrics/ClassLength # @since 0.7.0 # @api private def self.schema_type(entity) type = Sql::Types::Schema::AssociationType.new(entity) Types::Strict::Array.member(type) @@ -175,18 +175,25 @@ # Returns primary key and foreign key # # @since 0.7.0 # @api private def association_keys - relation(source) - .associations[target] + target_association .__send__(:join_key_map, container.relations) end + # Returns the targeted association for a given source + # # @since 0.7.0 # @api private + def target_association + relation(source).associations[target] + end + + # @since 0.7.0 + # @api private def _build_scope - result = relation(target) + result = relation(target_association.target.to_sym) result = result.where(foreign_key => subject.fetch(primary_key)) unless subject.nil? result.as(Model::MappedRelation.mapper_name) end # @since 0.7.0