Sha256: f4e7cd0d9892f8387fbefbc925c9194ac46eecda91204995952a78ccc548db97

Contents?: true

Size: 677 Bytes

Versions: 1

Compression:

Stored size: 677 Bytes

Contents

# frozen_string_literal: true

module Amoeba
  module Macros
    class HasAndBelongsToMany < ::Amoeba::Macros::Base
      def follow(relation_name, _association)
        clone = @cloner.amoeba.clones.include?(relation_name.to_sym)
        @old_object.__send__(relation_name).each do |old_obj|
          fill_relation(relation_name, old_obj, clone)
        end
      end

      def fill_relation(relation_name, old_obj, clone)
        # associate this new child to the new parent object
        old_obj = old_obj.amoeba_dup if clone
        relation_name = remapped_relation_name(relation_name)
        @new_object.__send__(relation_name) << old_obj
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amoeba-3.3.0 lib/amoeba/macros/has_and_belongs_to_many.rb