Module: ActiveRecordEx::ManyToMany::ClassMethods

Defined in:
lib/active_record_ex/many_to_many.rb

Instance Method Summary collapse

Instance Method Details

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



29
30
31
32
33
# File 'lib/active_record_ex/many_to_many.rb', line 29

def belongs_to(name, options={})
  subtypes = options.delete(:subtypes)
  super
  define_belongs_assoc(name, options.merge(subtypes: subtypes))
end

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



35
36
37
38
# File 'lib/active_record_ex/many_to_many.rb', line 35

def has_many(name, options = {}, &extension)
  super
  define_has_assoc(name.to_s.singularize, options)
end

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



40
41
42
43
# File 'lib/active_record_ex/many_to_many.rb', line 40

def has_one(name, options = {}, &extension)
  super
  define_has_assoc(name.to_s, options)
end

#singularize(method_name) ⇒ Object



45
46
47
48
49
# File 'lib/active_record_ex/many_to_many.rb', line 45

def singularize(method_name)
  define_method(method_name) do |*params|
    ModelArel.new(self).send(method_name, *params)
  end
end