Open Kilian-Perisset opened 5 years ago
Any work on this?
any update on this? @LoveAndCoding
Hi,
Mock-Sequelize doesn't seem to support the "include" property from Sequelize. Here is an example of use :
const db = {}; // Creating a fake sector table db.sector = dbMock.define( 'sector', { name: 'Test sector', event_id: 1, created_at: '2018-11-18 00:00:01', updated_at: '2018-11-18 00:00:01', deleted_at: null, }); // Creating a fake event table db.event = dbMock.define('event', { name: 'Test event, created_at: '2018-11-18 00:00:01', updated_at: '2018-11-18 00:00:01', deleted_at: null, }); // Creating a relationship between sector and event db.sector.belongsTo(db.event, { foreignKey: 'event_id' });
Above, I created two fake tables and now I want to get the event relative to a sector based on his id. So I have three choices :
1- Get the event with the function
sector.getEvent()
after getting my sector through a query. 2- Get the event through a query (like :event.findOne(... where: {id : sector.event_id}...)
) 3- Get the event through the propertyinclude
like this :const sectorsQuery = { where: { id: params.id }, include: [ { model: db.event, required: true, } ] }; const sector = await db.sector.findOne(sectorsQuery);
But the last one doesn't work with SequelizeMock and I don't know why... Why does the
include
property works well when I use Sequelize but not SequelizeMock ?Do you have any functional examples of use ? for 1, N and N, M queries ? Or this feature is not (yet) supported by SequelizeMock ?
Thank you.
@Shagequi were you able find any alternative to this?
Hi,
Mock-Sequelize doesn't seem to support the "include" property from Sequelize. Here is an example of use :
Above, I created two fake tables and now I want to get the event relative to a sector based on his id. So I have three choices :
1- Get the event with the function
sector.getEvent()
after getting my sector through a query. 2- Get the event through a query (like :event.findOne(... where: {id : sector.event_id}...)
) 3- Get the event through the propertyinclude
like this :But the last one doesn't work with SequelizeMock and I don't know why... Why does the
include
property works well when I use Sequelize but not SequelizeMock ?Do you have any functional examples of use ? for 1, N and N, M queries ? Or this feature is not (yet) supported by SequelizeMock ?
Thank you.