Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include property (for associations) seems to be not supported #68

Open
Kilian-Perisset opened this issue Jan 3, 2019 · 3 comments
Open

Comments

@Kilian-Perisset
Copy link

Kilian-Perisset commented Jan 3, 2019

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 property include 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.

@jpwiddy
Copy link

jpwiddy commented Feb 13, 2020

Any work on this?

@salauddinn
Copy link

salauddinn commented Feb 26, 2020

any update on this?
@LoveAndCoding

@salauddinn
Copy link

salauddinn commented Feb 26, 2020

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 property include 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants