不要怂,就是干,撸起袖子干!

Commit 63978e18 by Guillaume GRIMBERT Committed by Sushant

fix(findAll/deep-nested-includes): incorrect alias with `->` when subquery still…

… using `.` #7742 (#7795)
1 parent 0da021cd
......@@ -1457,7 +1457,7 @@ const QueryGenerator = {
// The main model attributes is not aliased to a prefix
joinOn = `${this.quoteTable(parent.as || parent.model.name)}.${this.quoteIdentifier(attrLeft)}`;
} else {
joinOn = this.quoteIdentifier(`${asLeft}.${attrLeft}`);
joinOn = this.quoteIdentifier(`${asLeft.replace(/->/g, '.')}.${attrLeft}`);
}
}
......
......@@ -2053,5 +2053,49 @@ describe(Support.getTestDialectTeaser('Include'), () => {
expect(posts[0].Entity.tags[0].EntityTag.entity_id).to.equal(posts[0].post_id);
});
});
it('should be able to generate a correct request with inner and outer join', function() {
const Customer = this.sequelize.define('customer', {
name: DataTypes.STRING
});
const ShippingAddress = this.sequelize.define('shippingAddress', {
address: DataTypes.STRING,
verified: DataTypes.BOOLEAN
});
const Order = this.sequelize.define('purchaseOrder', {
description: DataTypes.TEXT
});
const Shipment = this.sequelize.define('shipment', {
trackingNumber: DataTypes.STRING
});
Customer.hasMany(ShippingAddress);
ShippingAddress.belongsTo(Customer);
Customer.hasMany(Order);
Order.belongsTo(Customer);
Shipment.belongsTo(Order);
Order.hasOne(Shipment);
return this.sequelize.sync({ force: true }).then(() => {
return Shipment.findOne({
include: [{
model: Order,
required: true,
include: [{
model: Customer,
include: [{
model: ShippingAddress,
where: { verified: true }
}]
}]
}]
});
});
});
});
});
......@@ -549,8 +549,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it(`throws an error indicating an incorrect alias was entered if an association
and alias exist but the alias doesn't match`, function() {
it('throws an error indicating an incorrect alias was entered if an association and alias exist but the alias doesn\'t match', function() {
const self = this;
return self.Worker.findOne({ include: [{ model: self.Task, as: 'Work' }] }).catch (err => {
expect(err.message).to.equal('Task is associated to Worker using an alias. You\'ve included an alias (Work), but it does not match the alias defined in your association.');
......@@ -711,8 +710,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it(`throws an error indicating an incorrect alias was entered if an association
and alias exist but the alias doesn't match`, function() {
it('throws an error indicating an incorrect alias was entered if an association and alias exist but the alias doesn\'t match', function() {
const self = this;
return self.Worker.findOne({ include: [{ model: self.Task, as: 'Work' }] }).catch (err => {
expect(err.message).to.equal('Task is associated to Worker using an alias. You\'ve included an alias (Work), but it does not match the alias defined in your association.');
......
......@@ -157,8 +157,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geography object', function() {
const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]},
polygon2 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
......
......@@ -159,8 +159,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geometry object', function() {
const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]},
polygon2 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
......
......@@ -417,7 +417,8 @@ if (current.dialect.supports.transactions) {
Task.create({ title: 'Get rich', active: false}),
(john, task1) => {
return john.setTasks([task1]);
}).then(() => {
})
.then(() => {
return self.sequelize.transaction(t1 => {
if (current.dialect.supports.lockOuterJoinFailure) {
......@@ -441,7 +442,6 @@ if (current.dialect.supports.transactions) {
lock: t1.LOCK.UPDATE,
transaction: t1
});
}
});
});
......@@ -464,7 +464,8 @@ if (current.dialect.supports.transactions) {
Task.create({ title: 'Die trying', active: false}),
(john, task1) => {
return john.setTasks([task1]);
}).then(() => {
})
.then(() => {
return self.sequelize.transaction(t1 => {
return User.find({
where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!