Module: ActiveRecord::Base::CompositeClassMethods

Defined in:
lib/composite_primary_keys/base.rb

Instance Method Summary collapse

Instance Method Details

#composite?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/composite_primary_keys/base.rb', line 72

def composite?
  true
end

#ids_to_s(many_ids, id_sep = CompositePrimaryKeys::ID_SEP, list_sep = ',', left_bracket = '(', right_bracket = ')') ⇒ Object

ids_to_s([,[7,3]]) -> “(1,2),(7,3)” ids_to_s([,[7,3]], ‘,’, ‘;’) -> “1,2;7,3”



78
79
80
# File 'lib/composite_primary_keys/base.rb', line 78

def ids_to_s(many_ids, id_sep = CompositePrimaryKeys::ID_SEP, list_sep = ',', left_bracket = '(', right_bracket = ')')
  many_ids.map {|ids| "#{left_bracket}#{CompositePrimaryKeys::CompositeKeys.new(ids)}#{right_bracket}"}.join(list_sep)
end

#primary_keyObject



64
65
66
# File 'lib/composite_primary_keys/base.rb', line 64

def primary_key
  primary_keys
end

#primary_key=(keys) ⇒ Object



68
69
70
# File 'lib/composite_primary_keys/base.rb', line 68

def primary_key=(keys)
  self.primary_keys = keys
end

#primary_keysObject



49
50
51
52
# File 'lib/composite_primary_keys/base.rb', line 49

def primary_keys
  @primary_keys = reset_primary_keys unless defined? @primary_keys
  @primary_keys
end

#reset_primary_keysObject

Don’t like this method name, but its modeled after how AR does it



55
56
57
58
59
60
61
62
# File 'lib/composite_primary_keys/base.rb', line 55

def reset_primary_keys #:nodoc:
  if self == base_class
    # CPK
    self.primary_keys = get_primary_key(base_class.name)
  else
    self.primary_keys = base_class.primary_keys
  end
end