Module: Superstore::Associations::ClassMethods

Defined in:
lib/superstore/associations.rb

Instance Method Summary collapse

Instance Method Details

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

Options

:class_name

Use if the class cannot be inferred from the association

:polymorphic

Specify if the association is polymorphic

Example:

class Driver < Superstore::Base
end
class Truck < Superstore::Base
end


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

def belongs_to(name, options = {})
  Superstore::Associations::Builder::BelongsTo.build(self, name, options)
end

#generated_association_methodsObject



33
34
35
36
37
38
39
# File 'lib/superstore/associations.rb', line 33

def generated_association_methods
  @generated_association_methods ||= begin
    mod = const_set(:GeneratedAssociationMethods, Module.new)
    include mod
    mod
  end
end

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



25
26
27
# File 'lib/superstore/associations.rb', line 25

def has_many(name, options = {})
  Superstore::Associations::Builder::HasMany.build(self, name, options)
end

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



29
30
31
# File 'lib/superstore/associations.rb', line 29

def has_one(name, options = {})
  Superstore::Associations::Builder::HasOne.build(self, name, options)
end