Skip to content

It seems to generate a broken query. #9095

Closed

Description

@aprilmintacpineda

What are you doing?

The where clause

import models from './models';
import Sequelize, { Op } from 'sequelize';

const resultsPerPage = 10;
const offset = (1 * resultsPerPage) - resultsPerPage;

const where = {
  [Op.or]: {
    name: {
      [Op.like]: '%elvis%'
    },
    description: {
      [Op.like]: '%elvis%'
    },
    first_name: Sequelize.where(Sequelize.col('User.first_name'), {
      [Op.like]: '%elvis%'
    }),
    middle_name: Sequelize.where(Sequelize.col('User.middle_name'), {
      [Op.like]: '%elvis%'
    }),
    surname: Sequelize.where(Sequelize.col('User.surname'), {
      [Op.like]: '%elvis%'
    })
  }
};

The query

No limit and offset : case #1
Promise.all([
  models.Service.count({
    where,
    include: [
      models.User
    ]
  }),
  models.Service.findAll({
    where,
    include: [
      models.User,
      models.ServiceType,
      models.Area,
      {
        model: models.Contact,
        include: [
          models.ContactType
        ]
      },
      {
        model: models.ServiceRating,
        include: [
          models.User
        ]
      }
    ],
    order: [
      [ 'created_at', 'desc' ],
      [ models.ServiceRating, 'created_at', 'desc' ],
      [ models.Area, 'area', 'asc' ]
    ]
  })
])
.then(values => {
  console.log(values);
});

Note that there is no limit on the code above. Here is the generated query:

SELECT
  `Service`.`service_id`,
  `Service`.`user_id`,
  `Service`.`cover_image`,
  `Service`.`name`,
  `Service`.`description`,
  `Service`.`created_at`,
  `Service`.`updated_at`,
  `Service`.`service_type_id`,
  `User`.`user_id` AS `User.user_id`,
  `User`.`first_name` AS `User.first_name`,
  `User`.`middle_name` AS `User.middle_name`,
  `User`.`surname` AS `User.surname`,
  `User`.`email` AS `User.email`,
  `User`.`password` AS `User.password`,
  `User`.`sex` AS `User.sex`,
  `User`.`profile_image` AS `User.profile_image`,
  `User`.`confirm_token` AS `User.confirm_token`,
  `User`.`is_confirmed` AS `User.is_confirmed`,
  `User`.`remember_token` AS `User.remember_token`,
  `User`.`created_at` AS `User.created_at`,
  `User`.`updated_at` AS `User.updated_at`,
  `ServiceType`.`service_type_id` AS `ServiceType.service_type_id`,
  `ServiceType`.`type` AS `ServiceType.type`,
  `ServiceType`.`description` AS `ServiceType.description`,
  `ServiceType`.`created_at` AS `ServiceType.created_at`,
  `ServiceType`.`updated_at` AS `ServiceType.updated_at`,
  `Areas`.`area_id` AS `Areas.area_id`,
  `Areas`.`area` AS `Areas.area`,
  `Areas`.`created_at` AS `Areas.created_at`,
  `Areas`.`updated_at` AS `Areas.updated_at`,
  `Areas->service_area`.`created_at` AS `Areas.service_area.created_at`,
  `Areas->service_area`.`updated_at` AS `Areas.service_area.updated_at`,
  `Areas->service_area`.`area_id` AS `Areas.service_area.area_id`,
  `Areas->service_area`.`service_id` AS `Areas.service_area.service_id`,
  `Contacts`.`contact_id` AS `Contacts.contact_id`,
  `Contacts`.`user_id` AS `Contacts.user_id`,
  `Contacts`.`service_id` AS `Contacts.service_id`,
  `Contacts`.`contact` AS `Contacts.contact`,
  `Contacts`.`created_at` AS `Contacts.created_at`,
  `Contacts`.`updated_at` AS `Contacts.updated_at`,
  `Contacts`.`contact_type_id` AS `Contacts.contact_type_id`,
  `Contacts->service_contact`.`created_at` AS `Contacts.service_contact.created_at`,
  `Contacts->service_contact`.`updated_at` AS `Contacts.service_contact.updated_at`,
  `Contacts->service_contact`.`service_id` AS `Contacts.service_contact.service_id`,
  `Contacts->service_contact`.`contact_id` AS `Contacts.service_contact.contact_id`,
  `Contacts->ContactType`.`contact_type_id` AS `Contacts.ContactType.contact_type_id`,
  `Contacts->ContactType`.`type` AS `Contacts.ContactType.type`,
  `Contacts->ContactType`.`description` AS `Contacts.ContactType.description`,
  `Contacts->ContactType`.`created_at` AS `Contacts.ContactType.created_at`,
  `Contacts->ContactType`.`updated_at` AS `Contacts.ContactType.updated_at`,
  `ServiceRatings`.`service_id` AS `ServiceRatings.service_id`,
  `ServiceRatings`.`user_id` AS `ServiceRatings.user_id`,
  `ServiceRatings`.`rating` AS `ServiceRatings.rating`,
  `ServiceRatings`.`feedback` AS `ServiceRatings.feedback`,
  `ServiceRatings`.`created_at` AS`ServiceRatings.created_at`,
  `ServiceRatings`.`updated_at` AS `ServiceRatings.updated_at`,
  `ServiceRatings->User`.`user_id` AS `ServiceRatings.User.user_id`,
  `ServiceRatings->User`.`first_name` AS `ServiceRatings.User.first_name`,
  `ServiceRatings->User`.`middle_name` AS `ServiceRatings.User.middle_name`,
  `ServiceRatings->User`.`surname` AS `ServiceRatings.User.surname`,
  `ServiceRatings->User`.`email` AS `ServiceRatings.User.email`,
  `ServiceRatings->User`.`password` AS `ServiceRatings.User.password`,
  `ServiceRatings->User`.`sex` AS `ServiceRatings.User.sex`,
  `ServiceRatings->User`.`profile_image` AS `ServiceRatings.User.profile_image`,
  `ServiceRatings->User`.`confirm_token` AS `ServiceRatings.User.confirm_token`,
  `ServiceRatings->User`.`is_confirmed` AS `ServiceRatings.User.is_confirmed`,
  `ServiceRatings->User`.`remember_token` AS `ServiceRatings.User.remember_token`,
  `ServiceRatings->User`.`created_at` AS `ServiceRatings.User.created_at`,
  `ServiceRatings->User`.`updated_at` AS `ServiceRatings.User.updated_at`
FROM `service` AS `Service`
LEFT OUTER JOIN
  `user` AS `User`
  ON `Service`.`user_id` = `User`.`user_id`
LEFT OUTER JOIN
  `service_type` AS `ServiceType`
  ON `Service`.`service_type_id` = `ServiceType`.`service_type_id`
LEFT OUTER JOIN (
  `service_area` AS `Areas->service_area`
  INNER JOIN
    `area` AS `Areas`
    ON `Areas`.`area_id` = `Areas->service_area`.`area_id`
  )
  ON `Service`.`service_id` = `Areas->service_area`.`service_id`
LEFT OUTER JOIN (
  `service_contact` AS `Contacts->service_contact`
  INNER JOIN `contact` AS `Contacts`
  ON `Contacts`.`contact_id` = `Contacts->service_contact`.`contact_id`
  )
  ON `Service`.`service_id` = `Contacts->service_contact`.`service_id`
LEFT OUTER JOIN
  `contact_type` AS `Contacts->ContactType`
  ON `Contacts`.`contact_type_id` = `Contacts->ContactType`.`contact_type_id`
LEFT OUTER JOIN
  `service_rating`AS `ServiceRatings`
  ON `Service`.`service_id` = `ServiceRatings`.`service_id`
LEFT OUTER JOIN
  `user` AS `ServiceRatings->User`
  ON `ServiceRatings`.`user_id` = `ServiceRatings->User`.`user_id`
WHERE (
  `Service`.`name` LIKE '%elvis%' OR
  `Service`.`description` LIKE '%elvis%' OR
  `User`.`first_name` LIKE '%elvis%' OR
  `User`.`middle_name` LIKE '%elvis%' OR
  `User`.`surname` LIKE '%elvis%'
)
ORDER BY
  `Service`.`created_at` DESC,
  `ServiceRatings`.`created_at` DESC,
  `Areas`.`area` ASC
;

This query works fine.

add Limit and Offset : case #2

If you add a limit. The query will break.

Promise.all([
  models.Service.count({
    where,
    include: [
      models.User
    ]
  }),
  models.Service.findAll({
    where,
    include: [
      models.User,
      models.ServiceType,
      models.Area,
      {
        model: models.Contact,
        include: [
          models.ContactType
        ]
      },
      {
        model: models.ServiceRating,
        include: [
          models.User
        ]
      }
    ],
    limit: resultsPerPage,
    offset,
    order: [
      [ 'created_at', 'desc' ],
      [ models.ServiceRating, 'created_at', 'desc' ],
      [ models.Area, 'area', 'asc' ]
    ]
  })
])
.then(values => {
  console.log(values);
});

Note that there is a limit and offset on the code above. Here is the generated query:

SELECT
  `Service`.*,
  `User`.`user_id` AS `User.user_id`,
  `User`.`first_name` AS `User.first_name`,
  `User`.`middle_name` AS `User.middle_name`,
  `User`.`surname` AS `User.surname`,
  `User`.`email` AS `User.email`,
  `User`.`password` AS `User.password`,
  `User`.`sex` AS `User.sex`,
  `User`.`profile_image` AS `User.profile_image`,
  `User`.`confirm_token` AS `User.confirm_token`,
  `User`.`is_confirmed` AS `User.is_confirmed`,
  `User`.`remember_token` AS `User.remember_token`,
  `User`.`created_at` AS `User.created_at`,
  `User`.`updated_at` AS `User.updated_at`,
  `ServiceType`.`service_type_id` AS `ServiceType.service_type_id`,
  `ServiceType`.`type` AS `ServiceType.type`,
  `ServiceType`.`description` AS `ServiceType.description`,
  `ServiceType`.`created_at` AS `ServiceType.created_at`,
  `ServiceType`.`updated_at` AS `ServiceType.updated_at`,
  `Areas`.`area_id` AS `Areas.area_id`,
  `Areas`.`area` AS `Areas.area`,
  `Areas`.`created_at` AS `Areas.created_at`,
  `Areas`.`updated_at` AS `Areas.updated_at`,
  `Areas->service_area`.`created_at` AS `Areas.service_area.created_at`,
  `Areas->service_area`.`updated_at` AS `Areas.service_area.updated_at`,
  `Areas->service_area`.`area_id` AS `Areas.service_area.area_id`,
  `Areas->service_area`.`service_id` AS `Areas.service_area.service_id`,
  `Contacts`.`contact_id` AS `Contacts.contact_id`,
  `Contacts`.`user_id` AS `Contacts.user_id`,
  `Contacts`.`service_id` AS `Contacts.service_id`,
  `Contacts`.`contact` AS `Contacts.contact`,
  `Contacts`.`created_at` AS `Contacts.created_at`,
  `Contacts`.`updated_at` AS `Contacts.updated_at`,
  `Contacts`.`contact_type_id` AS `Contacts.contact_type_id`,
  `Contacts->service_contact`.`created_at` AS `Contacts.service_contact.created_at`,
  `Contacts->service_contact`.`updated_at` AS `Contacts.service_contact.updated_at`,
  `Contacts->service_contact`.`service_id` AS `Contacts.service_contact.service_id`,
  `Contacts->service_contact`.`contact_id` AS `Contacts.service_contact.contact_id`,
  `Contacts->ContactType`.`contact_type_id` AS `Contacts.ContactType.contact_type_id`, `Contacts->ContactType`.`type` AS
  `Contacts.ContactType.type`,
  `Contacts->ContactType`.`description` AS `Contacts.ContactType.description`,
  `Contacts->ContactType`.`created_at` AS `Contacts.ContactType.created_at`,
  `Contacts->ContactType`.`updated_at` AS `Contacts.ContactType.updated_at`,
  `ServiceRatings`.`service_id` AS `ServiceRatings.service_id`,
  `ServiceRatings`.`user_id` AS `ServiceRatings.user_id`,
  `ServiceRatings`.`rating` AS `ServiceRatings.rating`,
  `ServiceRatings`.`feedback` AS `ServiceRatings.feedback`,
  `ServiceRatings`.`created_at` AS `ServiceRatings.created_at`,
  `ServiceRatings`.`updated_at` AS `ServiceRatings.updated_at`,
  `ServiceRatings->User`.`user_id` AS `ServiceRatings.User.user_id`,
  `ServiceRatings->User`.`first_name` AS `ServiceRatings.User.first_name`,
  `ServiceRatings->User`.`middle_name` AS `ServiceRatings.User.middle_name`,
  `ServiceRatings->User`.`surname` AS `ServiceRatings.User.surname`,
  `ServiceRatings->User`.`email` AS `ServiceRatings.User.email`,
  `ServiceRatings->User`.`password` AS `ServiceRatings.User.password`,
  `ServiceRatings->User`.`sex` AS `ServiceRatings.User.sex`,
  `ServiceRatings->User`.`profile_image` AS `ServiceRatings.User.profile_image`,
  `ServiceRatings->User`.`confirm_token` AS `ServiceRatings.User.confirm_token`,
  `ServiceRatings->User`.`is_confirmed` AS `ServiceRatings.User.is_confirmed`,
  `ServiceRatings->User`.`remember_token` AS `ServiceRatings.User.remember_token`,
  `ServiceRatings->User`.`created_at` AS `ServiceRatings.User.created_at`,
  `ServiceRatings->User`.`updated_at` AS `ServiceRatings.User.updated_at`
FROM (
  SELECT
    `Service`.`service_id`,
    `Service`.`user_id`,
    `Service`.`cover_image`,
    `Service`.`name`,
    `Service`.`description`,
    `Service`.`created_at`,
    `Service`.`updated_at`,
    `Service`.`service_type_id`
  FROM `service` AS `Service`
  WHERE (
    `Service`.`name` LIKE '%elvis%' OR
    `Service`.`description` LIKE '%elvis%' OR
    `User`.`first_name` LIKE '%elvis%' OR
    `User`.`middle_name` LIKE '%elvis%' OR
    `User`.`surname` LIKE '%elvis%'
  )
  ORDER BY
    `Service`.`created_at` DESC LIMIT 0, 10
  ) AS `Service`
LEFT OUTER JOIN
  `user` AS `User`
  ON `Service`.`user_id` = `User`.`user_id`
LEFT OUTER JOIN
  `service_type` AS `ServiceType`
  ON `Service`.`service_type_id` = `ServiceType`.`service_type_id`
LEFT OUTER JOIN (
  `service_area` AS `Areas->service_area`
  INNER JOIN
    `area` AS `Areas` ON `Areas`.`area_id` = `Areas->service_area`.`area_id`
  )
  ON `Service`.`service_id` = `Areas->service_area`.`service_id`
LEFT OUTER JOIN (
  `service_contact` AS `Contacts->service_contact`
  INNER JOIN
    `contact` AS `Contacts` ON `Contacts`.`contact_id` = `Contacts->service_contact`.`contact_id`
  )
  ON `Service`.`service_id` = `Contacts->service_contact`.`service_id`
LEFT OUTER JOIN
  `contact_type` AS `Contacts->ContactType`
  ON `Contacts`.`contact_type_id` = `Contacts->ContactType`.`contact_type_id`
LEFT OUTER JOIN
  `service_rating` AS `ServiceRatings`
  ON `Service`.`service_id` = `ServiceRatings`.`service_id`
LEFT OUTER JOIN
  `user` AS `ServiceRatings->User`
  ON `ServiceRatings`.`user_id` = `ServiceRatings->User`.`user_id`
ORDER BY
  `Service`.`created_at` DESC,
  `ServiceRatings`.`created_at` DESC,
  `Areas`.`area` ASC
;

This query will not work and will result to SequelizeDatabaseError: Unknown column 'User.first_name' in 'where clause'.

Add only offset and not limit : case #3

If you add offset only but not limit it generates the desired query.

Promise.all([
  models.Service.count({
    where,
    include: [
      models.User
    ]
  }),
  models.Service.findAll({
    where,
    include: [
      models.User,
      models.ServiceType,
      models.Area,
      {
        model: models.Contact,
        include: [
          models.ContactType
        ]
      },
      {
        model: models.ServiceRating,
        include: [
          models.User
        ]
      }
    ],
    offset,
    order: [
      [ 'created_at', 'desc' ],
      [ models.ServiceRating, 'created_at', 'desc' ],
      [ models.Area, 'area', 'asc' ]
    ]
  })
])
.then(values => {
  console.log(values);
});

The following query was generated:

SELECT
  `Service`.`service_id`,
  `Service`.`user_id`,
  `Service`.`cover_image`,
  `Service`.`name`,
  `Service`.`description`,
  `Service`.`created_at`, 
  `Service`.`updated_at`,
  `Service`.`service_type_id`,
  `User`.`user_id` AS `User.user_id`,
  `User`.`first_name` AS `User.first_name`,
  `User`.`middle_name` AS `User.middle_name`,
  `User`.`surname` AS `User.surname`,
  `User`.`email` AS `User.email`,
  `User`.`password` AS `User.password`,
  `User`.`sex` AS `User.sex`,
  `User`.`profile_image` AS `User.profile_image`,
  `User`.`confirm_token` AS `User.confirm_token`,
  `User`.`is_confirmed` AS `User.is_confirmed`,
  `User`.`remember_token` AS `User.remember_token`,
  `User`.`created_at` AS `User.created_at`,
  `User`.`updated_at` AS `User.updated_at`,
  `ServiceType`.`service_type_id` AS `ServiceType.service_type_id`,
  `ServiceType`.`type` AS `ServiceType.type`, 
  `ServiceType`.`description` AS `ServiceType.description`,
  `ServiceType`.`created_at` AS `ServiceType.created_at`,
  `ServiceType`.`updated_at` AS `ServiceType.updated_at`,
  `Areas`.`area_id` AS `Areas.area_id`,
  `Areas`.`area` AS `Areas.area`,
  `Areas`.`created_at` AS `Areas.created_at`,
  `Areas`.`updated_at` AS `Areas.updated_at`,
  `Areas->service_area`.`created_at` AS `Areas.service_area.created_at`, 
  `Areas->service_area`.`updated_at` AS `Areas.service_area.updated_at`,
  `Areas->service_area`.`area_id` AS `Areas.service_area.area_id`,
  `Areas->service_area`.`service_id` AS `Areas.service_area.service_id`,
  `Contacts`.`contact_id` AS `Contacts.contact_id`,
  `Contacts`.`user_id` AS `Contacts.user_id`,
  `Contacts`.`service_id` AS `Contacts.service_id`,
  `Contacts`.`contact` AS `Contacts.contact`,
  `Contacts`.`created_at` AS `Contacts.created_at`,
  `Contacts`.`updated_at` AS `Contacts.updated_at`,
  `Contacts`.`contact_type_id` AS `Contacts.contact_type_id`,
  `Contacts->service_contact`.`created_at` AS `Contacts.service_contact.created_at`,
  `Contacts->service_contact`.`updated_at` AS `Contacts.service_contact.updated_at`,
  `Contacts->service_contact`.`service_id` AS `Contacts.service_contact.service_id`,
  `Contacts->service_contact`.`contact_id` AS `Contacts.service_contact.contact_id`,
  `Contacts->ContactType`.`contact_type_id` AS `Contacts.ContactType.contact_type_id`,
  `Contacts->ContactType`.`type` AS `Contacts.ContactType.type`,
  `Contacts->ContactType`.`description` AS `Contacts.ContactType.description`,
  `Contacts->ContactType`.`created_at` AS `Contacts.ContactType.created_at`,
  `Contacts->ContactType`.`updated_at` AS `Contacts.ContactType.updated_at`,
  `ServiceRatings`.`service_id` AS `ServiceRatings.service_id`,
  `ServiceRatings`.`user_id` AS `ServiceRatings.user_id`,
  `ServiceRatings`.`rating` AS `ServiceRatings.rating`,
  `ServiceRatings`.`feedback` AS `ServiceRatings.feedback`,
  `ServiceRatings`.`created_at` AS`ServiceRatings.created_at`,
  `ServiceRatings`.`updated_at` AS `ServiceRatings.updated_at`,
  `ServiceRatings->User`.`user_id` AS `ServiceRatings.User.user_id`,
  `ServiceRatings->User`.`first_name` AS `ServiceRatings.User.first_name`,
  `ServiceRatings->User`.`middle_name` AS `ServiceRatings.User.middle_name`,
  `ServiceRatings->User`.`surname` AS `ServiceRatings.User.surname`,
  `ServiceRatings->User`.`email` AS `ServiceRatings.User.email`,
  `ServiceRatings->User`.`password` AS `ServiceRatings.User.password`,
  `ServiceRatings->User`.`sex` AS `ServiceRatings.User.sex`,
  `ServiceRatings->User`.`profile_image` AS `ServiceRatings.User.profile_image`,
  `ServiceRatings->User`.`confirm_token` AS `ServiceRatings.User.confirm_token`,
  `ServiceRatings->User`.`is_confirmed` AS `ServiceRatings.User.is_confirmed`,
  `ServiceRatings->User`.`remember_token` AS `ServiceRatings.User.remember_token`,
  `ServiceRatings->User`.`created_at` AS `ServiceRatings.User.created_at`,
  `ServiceRatings->User`.`updated_at` AS `ServiceRatings.User.updated_at`
FROM
  `service` AS `Service`
LEFT OUTER JOIN
  `user` AS `User`
  ON `Service`.`user_id` = `User`.`user_id`
LEFT OUTER JOIN
  `service_type` AS `ServiceType`
  ON `Service`.`service_type_id` = `ServiceType`.`service_type_id`
LEFT OUTER JOIN (
  `service_area` AS `Areas->service_area`
  INNER JOIN
    `area` AS `Areas`
    ON `Areas`.`area_id` = `Areas->service_area`.`area_id`
  )
  ON `Service`.`service_id` = `Areas->service_area`.`service_id`
LEFT OUTER JOIN (
  `service_contact` AS `Contacts->service_contact`
  INNER JOIN `contact` AS `Contacts`
    ON `Contacts`.`contact_id` = `Contacts->service_contact`.`contact_id`
  )
  ON `Service`.`service_id` = `Contacts->service_contact`.`service_id`
LEFT OUTER JOIN
  `contact_type` AS `Contacts->ContactType`
  ON `Contacts`.`contact_type_id` = `Contacts->ContactType`.`contact_type_id`
LEFT OUTER JOIN
  `service_rating`AS `ServiceRatings`
  ON `Service`.`service_id` = `ServiceRatings`.`service_id`
LEFT OUTER JOIN
  `user` AS `ServiceRatings->User`
  ON `ServiceRatings`.`user_id` = `ServiceRatings->User`.`user_id`
WHERE (
  `Service`.`name` LIKE '%elvis%' OR
  `Service`.`description` LIKE '%elvis%' OR
  `User`.`first_name` LIKE '%elvis%' OR
  `User`.`middle_name` LIKE '%elvis%' OR
  `User`.`surname` LIKE '%elvis%'
)
ORDER BY
  `Service`.`created_at` DESC,
  `ServiceRatings`.`created_at` DESC,
  `Areas`.`area` ASC
LIMIT 0, 10000000000000;

This query will work and this is the actual desired query.

What do you expect to happen?

I expected case #3 to happen when I use limit and offset.

Note that even if you leave offset behind and set only limit the query still breaks.

Dialect: mysql
Dialect version: Can someone explain what this is asking about, please?
Database version: mysql Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64) using EditLine wrapper
Sequelize version: @4.33.4
Tested with latest release: @4.33.4

Activity

  1. danistefanovic commented on Feb 23, 2018

    @danistefanovic

    I've noticed the exact same issue. A LIMIT generates a subquery that breaks WHERE conditions which contain associations.

  2. aprilmintacpineda commented on Feb 23, 2018

    @aprilmintacpineda
    Author

    @danistefanovic did you manage to solve it?

  3. danistefanovic commented on Feb 23, 2018

    @danistefanovic

    In my case, I'm not expecting a lot results from findAll (~ 1-5 rows) and so I'm limiting the final result in JS at the moment.

  4. aprilmintacpineda commented on Feb 23, 2018

    @aprilmintacpineda
    Author

    That will work, but I think it's better to handle that on the SQL side since if you fetch 1000 data and want only ~ 1-5 rows it will be inefficient.

    as a workaround we can do:

    sequelize.query(
    `whatever I want`
    )
    .then(results => {
      // process
    })

    but it's still inefficient for a complicated query with lots of associations. Plus every time you change the models you'll have to manually update that query.

    This issue has been around since 2017, I wonder why it hasn't gained any attention.

  5. danistefanovic commented on Feb 23, 2018

    @danistefanovic

    I completely agree with you that it's not optimal. I'm fetching 1-5 rows but in some cases, I have to limit it to 1 row. Doing this in JS is just a quick and dirty workaround for now.

    The raw query option is not suitable for me because some of my scopes are more complex and I don't want to spread this logic around my code base.

  6. NicTorgersen commented on Feb 23, 2018

    @NicTorgersen

    Hooking onto this.

    Limit on a query where there are included models does not work at all, this is actually a huge issue.

  7. changed the title [-]adding limit generates a different query and breaks it.[/-] [+]Where with `limit` generates a broken query.[/+] on Feb 26, 2018
  8. changed the title [-]Where with `limit` generates a broken query.[/-] [+]It seems to generate a broken query.[/+] on Feb 26, 2018
  9. EdouardDubois commented on Feb 26, 2018

    @EdouardDubois

    I'm having the same problem with the limit included in the findOne, in the meantime thanks for the workaround.

  10. sushantdhiman commented on Apr 7, 2018

    @sushantdhiman
    Contributor

    Moved to #9166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions