Skip to content

Commit

Permalink
Don't try to select the primary key for models without primary key. C…
Browse files Browse the repository at this point in the history
…loses #4607
  • Loading branch information
janmeier committed Oct 11, 2015
1 parent 492dad2 commit f6b7855
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Next
- [FIXED] Partial rollback of datatype validations by hiding it behind the `typeValidation` flag.
- [FIXED] Don't try to select the primary key for models without primary key [#4607](https://github.com/sequelize/sequelize/issues/4607)

# 3.11.0
- [INTERNALS] Updated dependencies [#4594](https://github.com/sequelize/sequelize/pull/4594)
Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ Model.prototype.findAll = function(options) {
validateIncludedElements.call(this, options, tableNames);

// If we're not raw, we have to make sure we include the primary key for deduplication
if (!options.raw && options.attributes.indexOf(this.primaryKeyAttribute) === -1) {
if (options.attributes && !options.raw && this.primaryKeyAttribute && options.attributes.indexOf(this.primaryKeyAttribute) === -1) {
options.originalAttributes = options.attributes;
options.attributes = [this.primaryKeyAttribute].concat(options.attributes);
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/model/findall.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ describe(Support.getTestDialectTeaser('Model'), function() {
]);
});
});

it('works for models without PK #4607', function () {
var Model = current.define('model', {}, { timestamps: false });
var Foo = current.define('foo');
Model.hasOne(Foo);

Model.removeAttribute('id');

return Model.findAll({
attributes: {
include: ['name']
},
include: [Foo]
}).bind(this).then(function () {
expect(this.stub.getCall(0).args[2].attributes).to.deep.equal([
'name'
]);
});
});
});
});
});

0 comments on commit f6b7855

Please sign in to comment.