Changelog
0.6.0
Breaking changes:
QuerySet.filter
or QuerySet.exclude
with an object argument, any values of that object that look like a Model
instance (i.e. they have a getId
property that is a function), will be turned into the id of that instance before performing the filtering or excluding.E.g.
Book.filter({ author: Author.withId(0) });
Is equivalent to
Book.filter({ author: 0 });
Changelog
0.5.0
Breaking changes:
equals(otherModel)
now checks if the two model's attributes are shallow equal. Previously, it checked if the id's and model classes are equal.new
operator).Other changes:
hasId
static method to the Model class. It tests for the existence of the supplied id in the model's state.getNextState
to the Session class. This enables you to get the next state without running model-reducers. Useful if you're bootstrapping data, writing tests, or otherwise operating on the data outside reducers. You can pass an options object that currently accepts a runReducers
key. It's value indicates if reducers should be run or not.Changelog
0.4.0
undefined
, getNextState
will be called for you.Breaking changes:
Model.setOrder()
and Backend.order
. If you want ordered entities, use the QuerySet instance method orderBy
.update
. If you need to record updates dynamically based on each entity, iterate through the objects with forEach
and record updates separately:const authors = publisher.authors;
authors.forEach(author => {
const isAdult = author.age >= 18;
author.update({ isAdult });
})
or use the ability to merge an object with all objects in a QuerySet. Since the update operation is batched for all objects in the QuerySet, it can be more performant with a large amount of entities:
const authors = publisher.authors;
const isAdult = author => author.age >= 18;
const adultAuthors = authors.filter(isAdult);
adultAuthors.update({ isAdult: true });
const youngAuthors = authors.exclude(isAdult);
youngAuthors.update({ isAdult: false });
Changelog
0.3.1
A descriptive error is now thrown when a reverse field conflicts with another field declaration. For example, the following schema:
class A extends Model {}
A.modelName = 'A';
class B extends Model {}
B.modelName = 'B';
B.fields = {
field1: one('A'),
field2: one('A'),
};
would try to define the reverse field b
on A
twice, throwing an error with an undescriptive message.
Changelog
0.3.0
Breaking changes:
Model.withId(id)
now throws if object with id id
does not exist in the database.Changelog
0.2.0
Includes various bugfixes and improvements.
Breaking changes:
plain
and models
instance attributes in QuerySet
with withRefs
and withModels
respectively. The attributes return a new QuerySet
instead of modifying the existing one. A ref
alias is also added for withRefs
, so you can do Book.ref.at(2)
.filter
, exclude
or orderBy
method on a QuerySet
instance, the withRefs
flag is always flipped off so that calling the same methods on the returned QuerySet
would use model instances in the operations. Previously the flag value remained after calling those methods..toPlain()
from QuerySet
is renamed to .toRefArray()
for clarity..toModelArray()
method to QuerySet
..objects()
method from QuerySet
. Use .toRefArray()
or .toModelArray()
instead..toPlain()
method from Model
, which returned a copy of the Model instance's property values. To replace that, ref
instance getter was added. It returns a reference to the plain JavaScript object in the database. So you can do Book.withId(0).ref
. If you need a copy, you can do Object.assign({}, Book.withId(0).ref)
..fromEmpty()
instance method from Schema
..setReducer()
instance method from Schema
. You can just do ModelClass.reducer = reducerFunc;
.