Sha256: a37daf7dd4810359bf154840794444da14cb5eff6cda527b1f1c3e6419f69218

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 Bytes

Contents

module NinjaModel
  module Associations
    class HasManyAssociation
      def initialize(owner, reflection)
        @owner, @reflection = owner, reflection
        @relation = reflection.klass.scoped.where(reflection.primary_key_name.to_sym.eq(owner.id))
      end

      delegate :each, :collect, :map, :to_a, :size, :blank?, :empty?, :to => :relation

      def method_missing(method, *args)
        if @relation.respond_to?(method)
          @relation.send(method, *args)
        else
          super
        end
      end

      def relation
        @relation
      end

      def inspect
        @relation.to_a.inspect
      end

      def replace(other_array)
        @current = other_array
      end

      def blank?
        @relation.blank?
      end

      def to_ary
        @relation.to_a
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ninja-model-0.6.2 lib/ninja_model/associations/has_many_association.rb
ninja-model-0.6.1 lib/ninja_model/associations/has_many_association.rb