Class: HasManyOptions

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

Overview

Used to build has_many 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, self_class_name, options = {}) ⇒ HasManyOptions

Returns a new instance of HasManyOptions.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sql_object/associatable.rb', line 39

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

  merged_options = defaults.merge(options)

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