The hasOne
relation specifies that this table has exactly one of another type of object,
specified by a foreign key in the other table. The foreign key is assumed to be the singular of this
object's tableName
with an _id
suffix, but a custom foreignKey
attribute may also be specified.
The hasMany
relation specifies that this object has one or more rows in another table which
match on this object's primary key. The foreign key is assumed to be the singular of this object's
tableName
with an _id
suffix, but a custom foreignKey
attribute may also be specified.
A reverse hasOne
relation, the belongsTo
, where the specified key in this table
matches the primary idAttribute
of another table.
A belongsToMany
relation is when there are many-to-many relation
between two models, with a joining table.
A morphOne
relation is a one-to-one polymorphic association from this model
to another model.
A morphMany
relation is a polymorphic many-to-one relation from this model
to many another models.
Defines the opposite end of a morphOne
or morphMany
relationship, where
the alternate end of the polymorphic model is defined.
Used to define passthrough relationships - hasOne
, hasMany
,
belongsTo
or belongsToMany
, "through" a Interim
model or collection.
Fetch a model based on the currently set attributes,
returning a model to the callback, along with any options.
Returns a deferred promise through the Bookshelf.Sync
.
If {require: true}
is set as an option, the fetch is considered
a failure if the model comes up blank.
Run the first
call on the sync
object to fetch a single model.
Jump the rest of the chain if the response doesn't exist...
Now, load all of the data into the model as necessary.
If the "withRelated" is specified, we also need to eager load all of the
data on the model, as a side-effect, before we ultimately jump into the
next step of the model. Since the columns
are only relevant to the current
level, ensure those are omitted from the options.
Eager loads relationships onto an already populated Model
instance.
Sets and saves the hash of model attributes, triggering a "creating" or "updating" event on the model, as well as a "saving" event, to bind listeners for any necessary validation, logging, etc. If an error is thrown during these events, the model will not be saved.
Handle both "key", value
and {key: value}
-style arguments.
If the model has timestamp columns, set them as attributes on the model, even if the "patch" option is specified.
Determine whether the model is new, based on whether the model has an idAttribute
or not.
If the object is being created, we merge any defaults here rather than during object creation.
Set the attributes on the model.
If there are any save constraints, set them on the model.
Gives access to the query
object in the options
, in case we need it
in any event handlers.
After a successful database save, the id is updated if the model was created
In case we need to reference the previousAttributes
for the this
in the following event handlers.
Reset the query builder, called internally each time a query is run.
Returns an instance of the query builder.
Creates and returns a new Sync
instance.
Helper for setting up the morphOne
or morphMany
relations.
Handles the response data for the model, returning from the model's fetch call. Todo: {silent: true, parse: true}, for parity with collection#set need to check on Backbone's status there, ticket #2636
Handle the related data loading on the model.
Model