Skip to content

Using a custom id creates incorrect mysql queries. #313

Description

@ptnplanet

I have not yet tried this with any other driver, but I can at least say, mysql is affected.

Here is a model definition using a custom id:

var Session = db.define('session', {
    id:        { type: 'text', size: 36 },
    data:      { type: 'text', big: true },
    expiresAt: { type: 'date' }
});

will correctly create the following table:

CREATE TABLE `session` (
  `id` varchar(36) NOT NULL DEFAULT '',
  `data` longtext,
  `expiresAt` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
)

But will select the id column twice on SELECT queries:

Session.one({ id: 'abc' }, function (err, sess) { /* ... */ });

results in

SELECT `id`, `id`, `data`, `expiresAt`
FROM `session`
WHERE `id` = 'abc' LIMIT 1

Notice the duplicate id column in the select query. This does not do any harm - it is just a cosmetic thing.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions