Module: ZendeskAPI::Associations::ClassMethods::HasMany

Defined in:
lib/zendesk_api/associations.rb

Instance Method Summary collapse

Instance Method Details

#has_many(resource_name_or_class, class_level_options = {}) ⇒ Object

Represents a parent-to-children association between resources. Options to pass in are: class, path.

Parameters:

  • resource_name_or_class (Symbol)

    The underlying resource name or class to get it from

  • class_level_options (Hash) (defaults to: {})

    The options to pass to the method definition.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/zendesk_api/associations.rb', line 136

def has_many(resource_name_or_class, class_level_options = {})
  if klass = class_level_options.delete(:class)
    resource_name = resource_name_or_class
  else
    klass = resource_name_or_class
    resource_name = klass.resource_name
  end

  class_level_association = build_association(klass, resource_name, class_level_options)
  class_level_association.merge!(:singular => false, :id_column => "#{resource_name}_ids")

  associations << class_level_association

  define_used(class_level_association)
  define_has_many_getter(class_level_association)
  define_has_many_setter(class_level_association)
end