Extends
Members
Type:
Model
Constructor
- data
- Type:
mixed - options optional
- Type:
Object - key optional
- Type:
Key Keyinstance representing primary key of the document- isNewRecord optional
- Type:
boolean - Default:
true - cas optional
- Type:
CAS If the item on the server contains a different CAS value, the operation will fail. Note that if this option is undefined, no comparison will be performed.
Model Instance constructor & prototype
Parameters:
Throws:
Methods
- options optional
- Type:
Object See
StorageAdapter.removefor available options- force optional
- Type:
Boolean - Default:
false performs destoy operation even with no
casvalue set- options optional
- Type:
Object See
StorageAdapter.insertfor available options- path
- Type:
[String, ...]orString property path
- include
- Type:
StringorArrayorObject - options optional
- Type:
Object - skipPopulated optional
- Type:
Boolean - Default:
true if false, associations will be reloaded even though they've been already loaded
- getOrFail optional
- Type:
Boolean - Default:
false if true, when there is an association which can not be found, the populate method will return rejected promise with the error
- options optional
- Type:
Object See
StorageAdapter.replacefor available options- force optional
- Type:
Boolean - Default:
false performs replace operation even with no
casvalue set- options optional
- Type:
Object either
StorageAdapter#insertorStorageAdapter#replaceoptions depending on whether the document is being saved for the first time- property optional
- Type:
string - data
- Type:
mixed InstanceError
- expiry
- Type:
integer time in seconds
- options
- Type:
Object see
StorageAdapter#touchfor available optionsStorageError
- data
- Type:
Object - options optional
- Type:
Object see
StorageAdapter#replacefor available options
Promise
deletes the document and all related reference documents from a bucket
Parameters:
Promise
Promise<[Document>, ...]
Promise<{mixed}>
converts object's associations to json objects with single property with value of key string returns object's serialized data
Returns:Promise<{mixed}>
Promise<Instance>
saves NEW document (fails if the document already exists in a bucket) to storage
with all its reference documents, if an error occurs,
an attempt for rollback is made, if the rollback fails,
the afterFailedRollback hook is triggered.
Parameters:
Promise<Instance>
Boolean
Returns true when property value is modified. (differs from what is stored in a bucket) When no property path is provided, it checks whether the whole dataset is equal to its settled (persisted) counterpart
Parameters:
Boolean
Example:
instance.isDirty();
// or
instance.isDirty('path.to.nested.property');
// or
instance.isDirty(['path', 'to', 'nested', 'property']);
Instance
populates model's referenced associations
Parameters:
Instance
Example:
user.populate('friends'); //single path
user.populate([
'friends',
'apps'
]); // multiple paths
user.populate({
path: 'friends',
populate: 'friends'
}); // Populates user's friends and friends of the friends
// You can combine these three styles to describe exactly what you want to populate
Promise<Instance>
Explicitly fetches itself from upstream. Works also with destroyed documents which have been soft-deleted due to paranoid=true option
Returns:Promise<Instance>
Promise<Instance>
replaces (updates) current document (fails if the document with the key does not exists) in a bucket
and synchronizes reference documents (indexes). If an error occur,
an attempt for rollback is made, if the rollback fails,
the afterFailedRollback hook is triggered for every document an atempt for rollback failed (includes failed refdocs operations)
Parameters:
Promise<Instance>
undefined
validates & tries to parse data values according to defined schema
Throws:
Returns:undefined
Promise<Instance>
shortcut method for calling Instance#replace / Instance#insert. if fresh instance is initialized
and the data are not persisted to bucket yet, insert is called. If the Instance
is already persisted, data are updated with replace method
Parameters:
Promise<Instance>
Instance
override Document.prototype.setData
Parameters:
Instance
Example:
instance.setData({some: 'data'}) // bulk set enumerable properties of provided data object
instance.setData('username', 'fogine') //writes to `username` property on data object
Object
Throws:
Object
Promise<Instance>
touches underlaying document and all its reference documents when an Error occurs, it tries to touch all remaining documents before failing
Parameters:
Throws:
Promise<Instance>
Instance
This is similar to seting data on the instance and then calling Instance#save,
(respectively Instance#replace) however in this case when the operation fails,
the Model's instance data are restored to the previous state.
Parameters:
Instance
Inherited Methods
- property optional
- Type:
string - options
- Type:
Object See StorageAdapter.remove for available options
- cas
- Type:
CAS DocumentError
CAS or null
CAS or null
mixed
Parameters:
mixed
StorageAdapter or null
StorageAdapter or null
boolean
boolean
Promise<Object>
Removes the document identified by its key. This is an atomic operation which always operates on single document only.
Parameters:
Promise<Object>
undefined
Parameters:
undefined
undefined
Throws:
undefined
string
string