Sha256: fad8eed88716ec9b02049730edd63e0309bb6cab1665e02a261d050981613275

Contents?: true

Size: 756 Bytes

Versions: 2

Compression:

Stored size: 756 Bytes

Contents

module ActiveData
  module Model
    module Associations
      class EmbedsMany < Association

        def collection?
          true
        end

        def define_reader target
          target.class_eval <<-EOS
            def #{name}
              @#{name} ||= begin
                association = self.class.reflect_on_association('#{name}')
                association.klass.collection
              end
            end
          EOS
        end

        def define_writer target
          target.class_eval <<-EOS
            def #{name}= value
              association = self.class.reflect_on_association('#{name}')
              @#{name} = association.klass.collection(value)
            end
          EOS
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_data-0.3.0 lib/active_data/model/associations/embeds_many.rb
active_data-0.2.0 lib/active_data/model/associations/embeds_many.rb