Class: DataMapper::Associations::HasManyAssociation

Inherits:
HasNAssociation show all
Defined in:
lib/data_mapper/associations/has_many_association.rb

Defined Under Namespace

Classes: Set

Constant Summary

Constants inherited from HasNAssociation

DataMapper::Associations::HasNAssociation::OPTIONS

Instance Attribute Summary

Attributes inherited from HasNAssociation

#options

Instance Method Summary collapse

Methods inherited from HasNAssociation

#activate!, #associated_columns, #associated_constant, #associated_constant_name, #associated_table, #constant, #finder_options, #foreign_key_column, #foreign_key_name, #foreign_key_type, #initialize, #key_table, #name, #primary_key_column, #to_sql

Constructor Details

This class inherits a constructor from DataMapper::Associations::HasNAssociation

Instance Method Details

#define_accessor(klass) ⇒ Object

Define the association instance method (i.e. Project#tasks)



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/data_mapper/associations/has_many_association.rb', line 9

def define_accessor(klass)
  klass.class_eval <<-EOS
    def #{@association_name}
      @#{@association_name} || (@#{@association_name} = DataMapper::Associations::HasManyAssociation::Set.new(self, #{@association_name.inspect}))
    end
    
    def #{@association_name}=(value)
      #{@association_name}.set(value)
    end
  EOS
end

#instance_variable_nameObject



25
26
27
28
29
30
31
# File 'lib/data_mapper/associations/has_many_association.rb', line 25

def instance_variable_name
  class << self
    attr_reader :instance_variable_name
  end
  
  @instance_variable_name = "@#{@association_name}"
end

#to_disassociate_sqlObject



21
22
23
# File 'lib/data_mapper/associations/has_many_association.rb', line 21

def to_disassociate_sql
  "UPDATE #{associated_table.to_sql} SET #{foreign_key_column.to_sql} = NULL WHERE #{foreign_key_column.to_sql} = ?"
end