Module: Xero::Associations::BelongsTo::ClassMethods

Defined in:
lib/xero/associations/belongs_to.rb

Instance Method Summary collapse

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xero/associations/belongs_to.rb', line 8

def belongs_to(association_name, options = {})

  attr_accessor :"#{association_name}_id"

  define_method association_name do
    instance_variable_get(:"@#{association_name}")
  end

  define_method "#{association_name}=" do |value|
    instance_variable_set(:"@#{association_name}", value)
    send "#{association_name}_id=", value.id
  end
end