Module: DatastaxRails::AttributeMethods::PrimaryKey
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/datastax_rails/attribute_methods/primary_key.rb
Overview
Methods for working with PKs
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #__id ⇒ Object
-
#id ⇒ Object
Returns the primary key value.
-
#id=(value) ⇒ Object
Sets the primary key value.
-
#id? ⇒ Boolean
Queries the primary key value.
-
#id_for_destroy ⇒ Object
Returns a primary key has for deletes.
-
#id_for_update ⇒ Object
Returns a primary key hash for updates.
-
#to_key ⇒ Object
Returns this record’s primary key value wrapped in an Array if one is available.
Instance Method Details
#__id ⇒ Object
31 32 33 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 31 def __id self.class.column_for_attribute(self.class.primary_key).type_cast_for_cql3(id) end |
#id ⇒ Object
Returns the primary key value.
27 28 29 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 27 def id read_attribute(self.class.primary_key) end |
#id=(value) ⇒ Object
Sets the primary key value.
36 37 38 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 36 def id=(value) write_attribute(self.class.primary_key, value) if self.class.primary_key end |
#id? ⇒ Boolean
Queries the primary key value.
41 42 43 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 41 def id? query_attribute(self.class.primary_key) end |
#id_for_destroy ⇒ Object
Returns a primary key has for deletes. Payload models override this.
22 23 24 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 22 def id_for_destroy id_for_update end |
#id_for_update ⇒ Object
Returns a primary key hash for updates. Wide models override this.
17 18 19 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 17 def id_for_update { self.class.primary_key.to_s => __id } end |
#to_key ⇒ Object
Returns this record’s primary key value wrapped in an Array if one is available.
11 12 13 14 |
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 11 def to_key key = id [key] if key end |