Module: ZendeskAPI::Associations::ClassMethods::Has

Defined in:
lib/zendesk_api/associations.rb

Instance Method Summary collapse

Instance Method Details

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

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


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zendesk_api/associations.rb', line 77

def has(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.singular_resource_name
  end

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

  associations << class_level_association

  define_used(class_level_association)
  define_has_getter(class_level_association)
  define_has_setter(class_level_association)
end