Skip to content

Literal queries not getting evaluated on through attributes #5602

Closed

Description

@xizhao

In a belongsToMany association, Sequelize.literal attributes do not show up in the response:

...
include: [{
  model: ModelA,
  attributes: [[Sequelize.literal('3'), 'normaltest']], // Shows up in response as ModelA.normaltest: 3
  through: {
    attributes: [[Sequelize.literal('3'), 'throughtest']] // Does not show up
  }
}]
...

Activity

  1. xizhao commented on Mar 16, 2016

    @xizhao
    Author

    A greater issue seems to be I am not able to specify which attributes are getting selected,

    i.e. attributes: ['attr1', 'attr2'] yields the same results at attributes: ['attr1']

  2. added
    type: bug
    on Mar 17, 2016
  3. mickhansen commented on Mar 17, 2016

    @mickhansen
    Contributor

    Please move the second comment seperate issue and show some code that verifies it.

    I can see definitely see mappings not working for through.attributes

  4. xizhao commented on May 17, 2016

    @xizhao
    Author

    If #1 is a symptom of #2, should we just rename this issue to that?

  5. janmeier commented on May 17, 2016

    @janmeier
    Member

    @xizhao I believe they are two separate issues

  6. PragnaGH commented on Mar 27, 2019

    @PragnaGH

    I am using sequelize 5.2.1

    I have used sequelize.literal in attributes but not working.
    Throwing error
    attr[0].includes is not a function
    at attributes.map.attr (sequelize/lib/dialects/abstract/query-generator.js:1382:29)

    when I removed the literal it is working.
    But I want to calculate distinct count of an item.
    like this:
    Sequelize.literal('count(distinct('id'))')

  7. marianyfs commented on Aug 22, 2019

    @marianyfs
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

    staletype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions