Module: DaisybillApi::Ext::Associations::ClassMethods

Defined in:
lib/daisybill_api/ext/associations.rb

Overview

TODO: Think about creating Association classes or Routing class

Instance Method Summary collapse

Instance Method Details

#foreign_keyObject



10
11
12
# File 'lib/daisybill_api/ext/associations.rb', line 10

def foreign_key
  @foreign_key
end

#foreign_key=(value) ⇒ Object



6
7
8
# File 'lib/daisybill_api/ext/associations.rb', line 6

def foreign_key=(value)
  @foreign_key = value
end

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



14
15
16
17
18
19
20
# File 'lib/daisybill_api/ext/associations.rb', line 14

def has_many(name, options = {})
  clazz = modulize options[:class]
  define_method name do |params = {}|
    params.merge!(:"#{self.class.singular_key}_id" => self.id)
    clazz.constantize.all(params)
  end
end