-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Sequelize getter produce invalid/repeating query when given an options object #2311
Copy link
Copy link
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
var co = require('co');
var Sequelize = require('sequelize');
var sequelize = new Sequelize('sequelize-test', 'root', '');
var A = sequelize.define('A', {});
var B = sequelize.define('B', {});
var C = sequelize.define('C', {});
A.hasMany(B);
B.belongsTo(A);
A.hasMany(C);
C.belongsTo(A);
co(function* () {
yield sequelize.sync({
force: true
});
var options = {
};
var a = yield A.create(options);
yield a.getBs(options);
yield a.getCs(options);
})();Generated sql:
Executing (default): INSERT INTO `As` (`id`,`createdAt`,`updatedAt`) VALUES (DEFAULT,'2014-09-20 19:25:09','2014-09-20 19:25:09');
Executing (default): SELECT `id`, `createdAt`, `updatedAt`, `AId` FROM `Bs` AS `B` WHERE (`B`.`AId`=1 AND 1=1);
Executing (default): SELECT `id`, `createdAt`, `updatedAt`, `AId` FROM `Cs` AS `C` WHERE (`C`.`AId`=1 AND 1=1 AND (`B`.`AId`=1 AND 1=1));
It seems query information is attached to the options object you can repeat the get calls to make the SELECT query as long as you want.
Example with 3 getBs(options) calls:
Executing (default): INSERT INTO `As` (`id`,`createdAt`,`updatedAt`) VALUES (DEFAULT,'2014-09-20 19:27:24','2014-09-20 19:27:24');
Executing (default): SELECT `id`, `createdAt`, `updatedAt`, `AId` FROM `Bs` AS `B` WHERE (`B`.`AId`=1 AND 1=1);
Executing (default): SELECT `id`, `createdAt`, `updatedAt`, `AId` FROM `Bs` AS `B` WHERE (`B`.`AId`=1 AND 1=1 AND (`B`.`AId`=1 AND 1=1));
Executing (default): SELECT `id`, `createdAt`, `updatedAt`, `AId` FROM `Bs` AS `B` WHERE (`B`.`AId`=1 AND 1=1 AND (`B`.`AId`=1 AND 1=1 AND (`B`.`AId`=1 AND 1=1)));
And what does the 1=1 do?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type