Skip to content

Specify the column for .count #4442

Closed

Description

@abhinav76

I am trying this

return Model.count({distinct:'col_name',where:{some condition}});

It isn't working and the corresponding sql query that it produces is:

SELECT count(DISTINCT(*)) AS count FROM mail_box AS mail_box WHERE mail_box.to_username = 'nikhil9999';

Activity

  1. abhinav76 commented on Sep 6, 2015

    @abhinav76
    Author
  2. janmeier commented on Sep 7, 2015

    @janmeier
    Member

    You're not going to get a response faster by pinging people - we'll respond when we have the time :)

    Currently specifying the column is not supported, so tagging this as a feature request

  3. added
    type: feature
    on Sep 7, 2015
  4. changed the title [-]DISTINCT with count[/-] [+]Specify the column for .count[/+] on Sep 7, 2015
  5. janmeier commented on Sep 7, 2015

    @janmeier
    Member

    This should only need a small amount of code + test, so if you have the time it'll be quicker if you fix it yourself and provide a PR than waiting till someone from core has time to do it

  6. abhinav76 commented on Sep 8, 2015

    @abhinav76
    Author

    @janmeier I've done it using literal. Thanks anyways.
    And also can i use diistinct along with include in findAll?some thing like this?

    return Mailbox.findAll({DISTINCT:'from_username',where:{to_username:username},include:[{model:Profile,required:true}]});

  7. abhinav76 commented on Sep 10, 2015

    @abhinav76
    Author

    also if I am able to include more than 1 table in the above query but the they should all be distinct from_username?

  8. janmeier commented on Sep 10, 2015

    @janmeier
    Member

    No, distinct is only supported for count and other aggregations

    I'm not sure what you mean by your second question?

  9. abhinav76 commented on Sep 10, 2015

    @abhinav76
    Author

    Actually i wanted to retrieve all the users who have sent message to the specific user along with their info from profile table. So is it any way I can do this?

  10. janmeier commented on Sep 10, 2015

    @janmeier
    Member

    Maybe, but I have no idea what your schema looks like. Also, that is probably better suited as a SO / google groups / IRC question - let's keep this issue restricted to count

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

Metadata

Metadata

Assignees

Labels

type: feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions