Class: DataMapper::Associations::BelongsToAssociation
- Inherits:
-
HasNAssociation
- Object
- HasNAssociation
- DataMapper::Associations::BelongsToAssociation
- Defined in:
- lib/data_mapper/associations/belongs_to_association.rb
Defined Under Namespace
Classes: Instance
Constant Summary
Constants inherited from HasNAssociation
Instance Attribute Summary
Attributes inherited from HasNAssociation
Instance Method Summary collapse
- #associated_constant ⇒ Object
-
#constant ⇒ Object
Reverse the natural order for BelongsToAssociations.
- #define_accessor(klass) ⇒ Object
- #foreign_key_name ⇒ Object
- #to_sql ⇒ Object
Methods inherited from HasNAssociation
#activate!, #associated_columns, #associated_constant_name, #associated_table, #finder_options, #foreign_key_column, #foreign_key_type, #initialize, #key_table, #name, #primary_key_column
Constructor Details
This class inherits a constructor from DataMapper::Associations::HasNAssociation
Instance Method Details
#associated_constant ⇒ Object
36 37 38 |
# File 'lib/data_mapper/associations/belongs_to_association.rb', line 36 def associated_constant @constant end |
#constant ⇒ Object
Reverse the natural order for BelongsToAssociations
35 |
# File 'lib/data_mapper/associations/belongs_to_association.rb', line 35 alias constant associated_constant |
#define_accessor(klass) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/data_mapper/associations/belongs_to_association.rb', line 8 def define_accessor(klass) klass.class_eval <<-EOS def create_#{@association_name}(options = {}) #{@association_name}_association.create(options) end def build_#{@association_name}(options = {}) #{@association_name}_association.build(options) end def #{@association_name} #{@association_name}_association.instance end def #{@association_name}=(value) #{@association_name}_association.set(value) end private def #{@association_name}_association @#{@association_name} || (@#{@association_name} = DataMapper::Associations::BelongsToAssociation::Instance.new(self, #{@association_name.inspect})) end EOS end |
#foreign_key_name ⇒ Object
40 41 42 |
# File 'lib/data_mapper/associations/belongs_to_association.rb', line 40 def foreign_key_name @foreign_key_name || @foreign_key_name = (@options[:foreign_key] || "#{name}_#{key_table.key.name}".to_sym) end |
#to_sql ⇒ Object
44 45 46 |
# File 'lib/data_mapper/associations/belongs_to_association.rb', line 44 def to_sql "JOIN #{key_table.to_sql} ON #{foreign_key_column.to_sql(true)} = #{primary_key_column.to_sql(true)}" end |