Module: DatastaxRails::AttributeMethods::PrimaryKey

Extended by:
ActiveSupport::Concern
Defined in:
lib/datastax_rails/attribute_methods/primary_key.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#idObject

Returns the primary key value.



21
22
23
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 21

def id
  read_attribute(self.class.primary_key)
end

#id=(value) ⇒ Object

Sets the primary key value.



26
27
28
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 26

def id=(value)
  write_attribute(self.class.primary_key, value) if self.class.primary_key
end

#id?Boolean

Queries the primary key value.

Returns:

  • (Boolean)


31
32
33
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 31

def id?
  query_attribute(self.class.primary_key)
end

#id_for_updateObject

Returns a primary key hash for updates. Wide models override this.



16
17
18
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 16

def id_for_update
  { self.class.primary_key.to_s => id }
end

#to_keyObject

Returns this record’s primary key value wrapped in an Array if one is available.



10
11
12
13
# File 'lib/datastax_rails/attribute_methods/primary_key.rb', line 10

def to_key
  key = id
  [key] if key
end