Class: Cequel::Model::LocalAssociation
- Inherits:
-
Object
- Object
- Cequel::Model::LocalAssociation
- Defined in:
- lib/cequel/model/local_association.rb
Instance Attribute Summary collapse
-
#clazz ⇒ Object
readonly
Returns the value of attribute clazz.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #dependent ⇒ Object
- #foreign_key_name ⇒ Object
-
#initialize(name, owning_class, options) ⇒ LocalAssociation
constructor
A new instance of LocalAssociation.
- #primary_key ⇒ Object
- #primary_key_name ⇒ Object
- #scope(instance) ⇒ Object
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, ) @name, @owning_class = name, owning_class @class_name = [:class_name] || name.to_s.classify.to_sym @foreign_key_name = [:foreign_key] end |
Instance Attribute Details
#clazz ⇒ Object (readonly)
Returns the value of attribute clazz.
7 8 9 |
# File 'lib/cequel/model/local_association.rb', line 7 def clazz @clazz end |
#name ⇒ Object (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
#dependent ⇒ Object
35 36 |
# File 'lib/cequel/model/local_association.rb', line 35 def dependent end |
#foreign_key_name ⇒ Object
23 24 25 |
# File 'lib/cequel/model/local_association.rb', line 23 def foreign_key_name @foreign_key_name ||= :"#{name}_id" end |
#primary_key ⇒ Object
15 16 17 |
# File 'lib/cequel/model/local_association.rb', line 15 def primary_key @primary_key ||= clazz.key_column end |
#primary_key_name ⇒ Object
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 |