0.20.0
See Milestone 0.20.0
Bug Fixes
#242 - if a sub document has an @Id field, fromDb will properly populate that field if there's a _id field in the DBO. In order to refactor the fromDb operator to be easier to maintain in the future, promiscuous mode no longer cascades from the a parent model to child models. Also, defining promiscuous mode in the dbConfig preferences of @Model is now deprecated and will be removed in the future. For now on, define promiscuous mode like this:
@Model({promiscuous: true})
class SomeModel ... etc
#243 - you can now assign a default value to an @Id decorated field in a sub document and it will properly map to and from _id. For example:
describe('#243 @Id fields should map to _id in dbo', () => {
@Model()
class Child extends SapiModelMixin() {
@Id()
id: ObjectID = new ObjectID();
}
@Model({
dbConfig: {
collection: 'users',
db: 'userDb'
}
})
class Parent extends SapiModelMixin() {
@Id()
id: ObjectID = new ObjectID();
@Db({model: Child})
children: Child[];
}
it('toDb', async () => {
const parent = new Parent();
parent.children = [
new Child(),
new Child()
];
const result = parent.toDb();
expect(ObjectID.isValid(result._id)).toBeTruthy();
expect(ObjectID.isValid(result.children[0]._id)).toBeTruthy();
expect(ObjectID.isValid(result.children[1]._id)).toBeTruthy();
});
});
Breaking Changes
See notes above on #242. This is being done on an ultra-minor version because as far as I'm aware, no project is using the promiscuous mode feature with sub-documents such that the cascading behavior was expected.
There were many cases where model.toJson() would marshall properties without @Json operators to a JSON dto. That is no longer the case. You need to explicitly decorate fields with @Json if you want them to be marshalled to a JSON dto.
Worth Noting
#246 injects useNewUrlParser=true into your MongoDB options.
Core Developers
If you work on SakuraApi core, and you use Webstorm, the .idea config now includes a setup for using Webstorm's debugger.