Class: BelongsToOptions

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

Returns a new instance of BelongsToOptions.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/activeleopard/assoc_options.rb', line 18

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

  defaults = {
    foreign_key: ("#{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



36
37
38
# File 'lib/activeleopard/assoc_options.rb', line 36

def other_join_column
  primary_key
end

#own_join_columnObject



32
33
34
# File 'lib/activeleopard/assoc_options.rb', line 32

def own_join_column
  foreign_key
end