Module: FmRest::Spyke::Model::RecordID
- Extended by:
- ActiveSupport::Concern
- Included in:
- FmRest::Spyke::Model
- Defined in:
- lib/fmrest/spyke/model/record_id.rb
Overview
Modifies Spyke models to use __record_id
instead of id
as the
"primary key" method, so that we can map a model class to a FM layout
with a field named id
without clobbering it.
The id
reader method still maps to the record ID for backwards
compatibility and because Spyke hardcodes its use at various points
through its codebase, but it can be safely overwritten (e.g. to map to
a FM field).
The recommended way to deal with a layout that maps an id
attribute
is to remap it in the model to something else, e.g. unique_id
.
Instance Attribute Summary collapse
-
#__mod_id ⇒ Integer
(also: #mod_id)
The record's modId.
-
#__record_id ⇒ Integer
(also: #record_id, #id)
The record's recordId.
Instance Method Summary collapse
- #__record_id? ⇒ Boolean (also: #record_id?, #persisted?)
-
#destroy(id = nil) ⇒ Object
Spyke override -- Use
__record_id
instead ofid
. -
#hash ⇒ Object
Spyke override -- Use
__record_id
instead ofid
. -
#inspect ⇒ String
Spyke override -- Renders class string with layout name and
record_id
.
Instance Attribute Details
#__mod_id ⇒ Integer Also known as: mod_id
Returns the record's modId.
28 29 30 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 28 def __mod_id @__mod_id end |
#__record_id ⇒ Integer Also known as: record_id, id
Returns the record's recordId.
23 24 25 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 23 def __record_id @__record_id end |
Instance Method Details
#__record_id? ⇒ Boolean Also known as: record_id?, persisted?
57 58 59 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 57 def __record_id? __record_id.present? end |
#destroy(id = nil) ⇒ Object
Spyke override -- Use __record_id
instead of id
82 83 84 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 82 def destroy(id = nil) new(__record_id: id).destroy end |
#hash ⇒ Object
Spyke override -- Use __record_id
instead of id
65 66 67 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 65 def hash __record_id.hash end |
#inspect ⇒ String
Spyke override -- Renders class string with layout name and
record_id
.
74 75 76 |
# File 'lib/fmrest/spyke/model/record_id.rb', line 74 def inspect "#<#{self.class}(layout: #{self.class.layout}) record_id: #{__record_id.inspect} #{inspect_attributes}>" end |