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


16
17
18
19
20
21
22
# File 'lib/superstore/associations.rb', line 16

def belongs_to(name, options = {})
  if options.delete(:superstore)
    Superstore::Associations::Builder::BelongsTo.build(self, name, options)
  else
    super
  end
end

#belongs_to_required_by_defaultObject



40
41
42
# File 'lib/superstore/associations.rb', line 40

def belongs_to_required_by_default
  false
end

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



24
25
26
27
28
29
30
# File 'lib/superstore/associations.rb', line 24

def has_many(name, options = {})
  if options.delete(:superstore)
    Superstore::Associations::Builder::HasMany.build(self, name, options)
  else
    super
  end
end

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



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

def has_one(name, options = {})
  if options.delete(:superstore)
    Superstore::Associations::Builder::HasOne.build(self, name, options)
  else
    super
  end
end