Class: BelongsToOptions

Inherits:
AssocOptions show all
Defined in:
lib/laris/larisrecord/associatable.rb

Instance Attribute Summary

Attributes inherited from AssocOptions

#class_name, #foreign_key, #primary_key

Instance Method Summary collapse

Methods inherited from AssocOptions

#model_class, #table_name

Constructor Details

#initialize(assoc_name, options = {}) ⇒ BelongsToOptions

Returns a new instance of BelongsToOptions.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/laris/larisrecord/associatable.rb', line 14

def initialize(assoc_name, options = {})
  defaults = {
    class_name: assoc_name.to_s.camelcase,
    foreign_key: "#{assoc_name}_id".to_sym,
    primary_key: :id
  }

  defaults.each do |attr, default|
    send("#{attr}=", (options[attr] || default))
  end
end