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_key ⇒ Object
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 21 22 23 |
# File 'lib/daisybill_api/ext/associations.rb', line 14 def has_many(name, = {}) clazz = modulize [:class] define_method name do |params = {}| params.merge!(:"#{self.class.singular_key}_id" => self.id) params.merge!(path: "#{show_path}/#{name}") if [:set_path] params.merge!(path: clazz.constantize.index_path(id)) if [:set_path] && [:use_path_prefix] params.merge!(collection_key: [:collection_key]) if [:collection_key] clazz.constantize.all(params) end end |