Class: Model

Model


new Model()

Base stamp for all models which wraps all raw JavaScript objects.
Not meant to be used directly more like mixin in other stamps.

Properties:
Name Type Description
_config Syncano

private attribute which holds Syncano object

_meta Meta

private attribute which holds Meta object

_constraints Object

private attribute which holds validation constraints

_request Request

private attribute which holds Request configuration

_querySet Request

private attribute which holds QuerySet stamp

Source:
Example
var MyModel = stampit()
    .compose(Model)
    .setMeta(MyMeta)
    .setConstraints(MyConstraints);

Methods


<static> fromJSON(rawJSON [, properties])

Used only for serialization for raw object to stamp.

Parameters:
Name Type Argument Default Description
rawJSON Object
properties Object <optional>
{}

some default properties which will be assigned to model instance

Source:
Returns:
Type
Model

<static> getQuerySet()

Gets QuerySet from stampit definition.

Source:
Returns:
Type
QuerySet
Example
var querySet = stampit().compose(Model).getQuerySet();

<static> please( [properties])

Returns QuerySet instance which allows to do ORM like operations on Syncano API.

Parameters:
Name Type Argument Default Description
properties Object <optional>
{}

some default properties for all ORM operations

Source:
Returns:
Type
QuerySet
Example
MyModel.please().list();

<static> setQuerySet(querySet)

Sets QuerySet and returns new stampit definition.

Parameters:
Name Type Description
querySet QuerySet

QuerySet definition

Source:
Returns:
Type
Model
Example
var MyStamp = stampit().compose(Model).setQuerySet({});

delete()

Removes the current instance.

Source:
Returns:
Type
Promise

isNew()

Checks if model instance if already saved.

Source:
Returns:
Type
Boolean

rename(payload)

Method used for making requests to the 'rename' endpoint in models.

Parameters:
Name Type Description
payload Object

object containing the payload to be sent

Source:
Returns:
Type
Promise
Example
Model.rename({ new_name: 'new_name'}).then(function(model) {});

save()

Creates or updates the current instance.

Source:
Returns:
Type
Promise

serialize()

Serializes raw JavaScript object into Model instance.

Source:
Returns:
Type
Model

validate()

Validates current model instance in context of defined constraints.

Source:
Returns:
Type
Object | undefined