Class: BelongsToOptions

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

Overview

Used to build belongs_to associations.

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(name, options = {}) ⇒ BelongsToOptions

Returns a new instance of BelongsToOptions.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sql_object/associatable.rb', line 22

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

  merged_options = defaults.merge(options)

  @primary_key = merged_options[:primary_key]
  @foreign_key = merged_options[:foreign_key]
  @class_name = merged_options[:class_name]
end