Module: ActiveRemote::PrimaryKey
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#primary_key ⇒ Object
Instance level access to either the default primary key, or whatever you configured the class level primary key to be.
-
#to_key ⇒ Object
Returns an Array of all key attributes if any of the attributes is set, whether or not the object is persisted.
Instance Method Details
#primary_key ⇒ Object
Instance level access to either the default primary key, or whatever you configured the class level primary key to be.
32 33 34 |
# File 'lib/active_remote/primary_key.rb', line 32 def primary_key self.class.primary_key end |
#to_key ⇒ Object
Returns an Array of all key attributes if any of the attributes is set, whether or not the object is persisted. Returns nil
if there are no key attributes.
class Person
include ActiveModel::Conversion
attr_accessor :id
def initialize(id)
@id = id
end
end
person = Person.new(1)
person.to_key # => [1]
50 51 52 53 |
# File 'lib/active_remote/primary_key.rb', line 50 def to_key @__to_key_key = respond_to?(primary_key) && send(primary_key) if @__to_key_key.nil? @__to_key_key ? [@__to_key_key] : nil end |