Class: Cequel::Model::RemoteAssociation
- Inherits:
-
Object
- Object
- Cequel::Model::RemoteAssociation
- Defined in:
- lib/cequel/model/remote_association.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#dependent ⇒ Object
readonly
Returns the value of attribute dependent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clazz ⇒ Object
- #foreign_key_name ⇒ Object
-
#initialize(name, owning_class, options) ⇒ RemoteAssociation
constructor
A new instance of RemoteAssociation.
- #primary_key ⇒ Object
- #primary_key_name ⇒ Object
- #scope(instance) ⇒ Object
Constructor Details
#initialize(name, owning_class, options) ⇒ RemoteAssociation
Returns a new instance of RemoteAssociation.
9 10 11 12 13 14 |
# File 'lib/cequel/model/remote_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] @dependent = [:dependent] end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
7 8 9 |
# File 'lib/cequel/model/remote_association.rb', line 7 def class_name @class_name end |
#dependent ⇒ Object (readonly)
Returns the value of attribute dependent.
7 8 9 |
# File 'lib/cequel/model/remote_association.rb', line 7 def dependent @dependent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cequel/model/remote_association.rb', line 7 def name @name end |
Instance Method Details
#clazz ⇒ Object
32 33 34 |
# File 'lib/cequel/model/remote_association.rb', line 32 def clazz @clazz ||= class_name.to_s.constantize end |
#foreign_key_name ⇒ Object
28 29 30 |
# File 'lib/cequel/model/remote_association.rb', line 28 def foreign_key_name @foreign_key_name ||= :"#{@owning_class.name.underscore}_id" end |
#primary_key ⇒ Object
20 21 22 |
# File 'lib/cequel/model/remote_association.rb', line 20 def primary_key @primary_key ||= @owning_class.key_column end |
#primary_key_name ⇒ Object
24 25 26 |
# File 'lib/cequel/model/remote_association.rb', line 24 def primary_key_name @primary_key_name ||= primary_key.name end |
#scope(instance) ⇒ Object
16 17 18 |
# File 'lib/cequel/model/remote_association.rb', line 16 def scope(instance) clazz.where(foreign_key_name => instance.__send__(primary_key_name)) end |