Module: DuckRecord::Associations::ClassMethods

Defined in:
lib/duck_record/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, scope = nil, options = {}) ⇒ Object



114
115
116
117
# File 'lib/duck_record/associations.rb', line 114

def belongs_to(name, scope = nil, options = {})
  reflection = Builder::BelongsTo.build(self, name, scope, options)
  Reflection.add_reflection self, name, reflection
end

#embeds_many(name, options = {}, &extension) ⇒ Object



104
105
106
107
# File 'lib/duck_record/associations.rb', line 104

def embeds_many(name, options = {}, &extension)
  reflection = Builder::EmbedsMany.build(self, name, nil, options, &extension)
  Reflection.add_reflection self, name, reflection
end

#embeds_one(name, options = {}) ⇒ Object



109
110
111
112
# File 'lib/duck_record/associations.rb', line 109

def embeds_one(name, options = {})
  reflection = Builder::EmbedsOne.build(self, name, nil, options)
  Reflection.add_reflection self, name, reflection
end

#has_many(name, scope = nil, options = {}, &extension) ⇒ Object



124
125
126
127
# File 'lib/duck_record/associations.rb', line 124

def has_many(name, scope = nil, options = {}, &extension)
  reflection = Builder::HasMany.build(self, name, scope, options, &extension)
  Reflection.add_reflection self, name, reflection
end

#has_one(name, scope = nil, options = {}) ⇒ Object



119
120
121
122
# File 'lib/duck_record/associations.rb', line 119

def has_one(name, scope = nil, options = {})
  reflection = Builder::HasOne.build(self, name, scope, options)
  Reflection.add_reflection self, name, reflection
end