Class: Cequel::Model::LocalAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/model/local_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, owning_class, options) ⇒ LocalAssociation

Returns a new instance of LocalAssociation.



9
10
11
12
13
# File 'lib/cequel/model/local_association.rb', line 9

def initialize(name, owning_class, options)
  @name, @owning_class = name, owning_class
  @class_name = options[:class_name] || name.to_s.classify.to_sym
  @foreign_key_name = options[:foreign_key]
end

Instance Attribute Details

#clazzObject (readonly)

Returns the value of attribute clazz.



7
8
9
# File 'lib/cequel/model/local_association.rb', line 7

def clazz
  @clazz
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cequel/model/local_association.rb', line 7

def name
  @name
end

Instance Method Details

#dependentObject



35
36
# File 'lib/cequel/model/local_association.rb', line 35

def dependent
end

#foreign_key_nameObject



23
24
25
# File 'lib/cequel/model/local_association.rb', line 23

def foreign_key_name
  @foreign_key_name ||= :"#{name}_id"
end

#primary_keyObject



15
16
17
# File 'lib/cequel/model/local_association.rb', line 15

def primary_key
  @primary_key ||= clazz.key_column
end

#primary_key_nameObject



19
20
21
# File 'lib/cequel/model/local_association.rb', line 19

def primary_key_name
  @primary_key_name ||= primary_key.name
end

#scope(instance) ⇒ Object



27
28
29
# File 'lib/cequel/model/local_association.rb', line 27

def scope(instance)
  clazz.where(primary_key_name => instance.__send__(foreign_key_name))
end