Class: HasManyOptions

Inherits:
AssocOptions show all
Defined in:
lib/activeleopard/assoc_options.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(name, self_class_name, options = {}) ⇒ HasManyOptions

Returns a new instance of HasManyOptions.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/activeleopard/assoc_options.rb', line 42

def initialize(name, self_class_name, options = {})
  name = name.to_s.singularize
  self_class_name = self_class_name.to_s.singularize

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

  defaults.merge(options).each do |option, opt_name|
    send("#{option}=", opt_name)
  end
end

Instance Method Details

#other_join_columnObject



61
62
63
# File 'lib/activeleopard/assoc_options.rb', line 61

def other_join_column
  foreign_key
end

#own_join_columnObject



57
58
59
# File 'lib/activeleopard/assoc_options.rb', line 57

def own_join_column
  primary_key
end