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

Commit db597c1d by Mick Hansen

Change some tests, break BC

1 parent 931cfaad
......@@ -13,7 +13,7 @@ module.exports = (function() {
this.as = this.options.as
if (this.isSelfAssociation && !this.options.foreignKey && !!this.as) {
this.options.foreignKey = Utils._.underscoredIf(Utils.singularize(this.as, this.source.options.language) + "Id", this.source.options.underscored)
this.options.foreignKey = Utils._.underscoredIf(Utils.singularize(this.source.tableName, this.source.options.language) + "Id", this.source.options.underscored)
}
if (!this.as) {
......@@ -38,7 +38,8 @@ module.exports = (function() {
, targetKeys = Object.keys(this.target.primaryKeys)
, keyType = ((this.target.hasPrimaryKeys && targetKeys.length === 1) ? this.target.rawAttributes[targetKeys[0]].type : DataTypes.INTEGER)
this.identifier = this.options.foreignKey || Utils._.underscoredIf(this.as + "Id", this.source.options.underscored)
this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.target.tableName, this.target.options.language) + "Id", this.source.options.underscored)
//this.identifier = this.options.foreignKey || Utils._.underscoredIf(this.as + "Id", this.source.options.underscored)
newAttributes[this.identifier] = { type: this.options.keyType || keyType }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.target, this.source, this.options)
Utils._.defaults(this.source.rawAttributes, newAttributes)
......
......@@ -437,7 +437,7 @@ module.exports = (function() {
options.attributes = optAttributes.join(', ')
}
var conditionalJoins = options.hasMultiAssociation && this.getConditionalJoins(options, factory),
var conditionalJoins = options.hasMultiAssociation && (options.limit || options.offset) && this.getConditionalJoins(options, factory),
query;
if (conditionalJoins) {
......@@ -613,7 +613,6 @@ module.exports = (function() {
, attributePart = associationParts.pop()
, self = this
return associationParts.every(function (attribute) {
var association = self.findAssociation(attribute, dao);
if (!association) return false;
......@@ -627,13 +626,15 @@ module.exports = (function() {
, attributePart = associationParts.pop()
, self = this
, association
, keyParts = []
associationParts.forEach(function (attribute) {
association = self.findAssociation(attribute, dao)
dao = self.findAssociation(attribute, dao).target;
dao = association.target;
keyParts.push(association.as || association.options.as || dao.tableName)
})
return (association.as || association.options.as || dao.tableName) + '.' + attributePart;
return this.quoteIdentifier(keyParts.join('.')) + '.' + this.quote(attributePart);
},
getConditionalJoins: function(options, originalDao){
......@@ -702,10 +703,12 @@ module.exports = (function() {
if(this.isAssociationFilter(key, dao)){
key = this.getAssociationFilterColumn(key, dao);
} else {
key = this.quoteIdentifiers(key)
}
//handle qualified key names
var _key = this.quoteIdentifiers(key)
var _key = key
, _value = null
if (Array.isArray(value)) {
......
......@@ -930,7 +930,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
describe('source belongs to target', function() {
beforeEach(function(done) {
this.A.belongsTo(this.B, { as: 'relation1' })
this.A.belongsTo(this.B)
this.A.hasMany(this.B, { as: 'relation2' })
this.B.hasMany(this.A, { as: 'relation2' })
......@@ -948,7 +948,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
a1
.save()
.then(function() { return b1.save() })
.then(function() { return a1.setRelation1(b1) })
.then(function() { return a1.setB(b1) })
.then(function() { return self.A.find({ where: { name: 'a1' } }) })
.done(function(a) {
expect(a.bId).to.be.eq(b1.id)
......@@ -959,7 +959,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
describe('target belongs to source', function() {
beforeEach(function(done) {
this.B.belongsTo(this.A, { as: 'relation1' })
this.B.belongsTo(this.A)
this.A.hasMany(this.B, { as: 'relation2' })
this.B.hasMany(this.A, { as: 'relation2' })
......@@ -977,7 +977,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
a1
.save()
.then(function() { return b1.save() })
.then(function() { return b1.setRelation1(a1) })
.then(function() { return b1.setA(a1) })
.then(function() { return self.B.find({ where: { name: 'b1' } }) })
.done(function(b) {
expect(b.aId).to.be.eq(a1.id)
......
......@@ -18,7 +18,6 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
Task.belongsTo(Project);
Project.hasMany(Task);
this.sequelize.sync({ force: true }).success(function() {
User.bulkCreate([{
username: 'leia'
......@@ -47,8 +46,15 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
Task.findAll({
where: {
'project.user.username': 'leia'
}
}).success(function(tasks){
},
include: [
{model: Project, include: [
User
]}
]
}).done(function(err, tasks){
expect(err).not.to.be.ok
try{
expect(tasks.length).to.be.equal(2);
expect(tasks[0].title).to.be.equal('fight empire');
......@@ -106,7 +112,12 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
where: {
'project.user.username': 'leia',
'project.user.id': 1
}
},
include: [
{model: Project, include: [
User
]}
]
}).success(function(tasks){
try{
expect(tasks.length).to.be.equal(2);
......@@ -134,7 +145,6 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
Task.belongsTo(Project);
Project.hasMany(Task);
this.sequelize.sync({ force: true }).success(function() {
User.bulkCreate([{
username: 'leia'
......@@ -164,8 +174,13 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
User.findAll({
where: {
'projects.tasks.title': 'fight empire'
}
}).success(function(users){
},
include: [
{model: Project, include: [
Task
]}
]
}).done(function(err, users){
try{
expect(users.length).to.be.equal(1);
expect(users[0].username).to.be.equal('leia');
......@@ -208,7 +223,10 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
User.findAll({
where: {
'projects.title': 'republic'
}
},
include: [
{model: Project}
]
}).success(function(users){
try{
expect(users.length).to.be.equal(1);
......
......@@ -920,8 +920,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
overdue_days: DataTypes.INTEGER
}, { timestamps: false })
this.UserEager.hasMany(this.ProjectEager, { as: 'Projects' })
this.ProjectEager.belongsTo(this.UserEager, { as: 'Poobah' })
this.UserEager.hasMany(this.ProjectEager, { as: 'Projects', foreignKey: 'ProjectId' })
this.ProjectEager.belongsTo(this.UserEager, { as: 'Poobah', foreignKey: 'ProjectId' })
self.UserEager.sync({force: true}).success(function() {
self.ProjectEager.sync({force: true}).success(function() {
......@@ -1016,7 +1016,6 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
self.ProjectEager.create({ title: 'party', overdue_days: 2 }).success(function(party) {
user.setProjects([homework, party]).success(function() {
self.ProjectEager.findAll({include: [{model: self.UserEager, as: 'Poobah'}]}).success(function(projects) {
expect(projects.length).to.equal(2)
expect(projects[0].poobah).to.exist
expect(projects[1].poobah).to.exist
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!