Skip to content

Commit d4dc42a

Browse files
committed
checkout nested queryable listener
1 parent 14480d2 commit d4dc42a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

OnExecuteNestedQueryable.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ class OnExecuteNestedQueryable {
4141
// try to upgrade
4242
return model.migrateAsync();
4343
}
44+
if (model == null) {
45+
// try to find if the given model is a pre-defined many-to-many association
46+
const attribute = event.model.attributes.filter((attr) => attr.many).find((attr) => {
47+
const mapping = event.model.inferMapping(attr.name);
48+
return mapping && mapping.associationAdapter === item.$entity.model;
49+
});
50+
if (attribute) {
51+
/**
52+
* use DataObjectJunction class as a helper for creating model
53+
* (get an instance of DataObjectJunction class using DataObject.property() method)
54+
* @type {import('./data-object-junction').DataObjectJunction}
55+
*/
56+
const junction = event.model.convert({}).property(attribute.name);
57+
return junction.getBaseModel().migrateAsync();
58+
}
59+
}
4460
}
4561
return Promise.resolve();
4662
}

data-context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var { DataModel } = require('./data-model');
3939
*/
4040
function DefaultDataContext()
4141
{
42+
DefaultDataContext.super_.bind(this)();
4243
/**
4344
* @type {import('./types').DataAdapter}
4445
*/

0 commit comments

Comments
 (0)