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

Commit 10029e1f by Sascha Depold

Make `references` an object

1 parent fbf4cee8
# Next
- [CHANGED] The `references` property of model attributes has been transformed to an object: `{type: Sequelize.INTEGER, references: { model: SomeModel, key: 'some_key' }}`. The former format is deprecated.
# 3.0.0
3.0.0 cleans up a lot of deprecated code, making it easier for us to develop and maintain features in the future.
......
......@@ -590,8 +590,10 @@ Series = sequelize.define('Series', {
// Set FK relationship (hasMany) with `Trainer`
trainer_id: {
type: DataTypes.INTEGER,
references: "Trainers",
referencesKey: "id"
references: {
model: "Trainers",
key: "id"
}
}
})
 
......@@ -609,8 +611,10 @@ Video = sequelize.define('Video', {
// set relationship (hasOne) with `Series`
series_id: {
type: DataTypes.INTEGER,
references: Series, // Can be both a string representing the table name, or a reference to the model
referencesKey: "id"
references: {
model: Series, // Can be both a string representing the table name, or a reference to the model
key: "id"
}
}
});
 
......
......@@ -15,8 +15,10 @@ module.exports = function(sequelize, DataTypes) {
// Set FK relationship (hasMany) with `Trainer`
trainer_id: {
type: DataTypes.INTEGER,
references: "Trainer",
referencesKey: 'id'
references: {
model: 'Trainer',
key: 'id'
}
}
}, {
// don't need timestamp attributes for this model
......
......@@ -15,8 +15,10 @@ module.exports = function(sequelize, DataTypes) {
// set relationship (hasOne) with `Series`
series_id: {
type: DataTypes.INTEGER,
references: "Series",
referencesKey: 'id'
references: {
model: 'Series',
key: 'id'
}
}
}, {
// don't need timestamp attributes for this model
......
......@@ -225,8 +225,10 @@ module.exports = (function() {
}
if (this.options.constraints !== false) {
sourceAttribute.references = this.source.getTableName();
sourceAttribute.referencesKey = sourceKeyField;
sourceAttribute.references = {
model: this.source.getTableName(),
key: sourceKeyField
};
// For the source attribute the passed option is the priority
sourceAttribute.onDelete = this.options.onDelete || this.through.model.rawAttributes[this.identifier].onDelete;
sourceAttribute.onUpdate = this.options.onUpdate || this.through.model.rawAttributes[this.identifier].onUpdate;
......@@ -234,9 +236,10 @@ module.exports = (function() {
if (!sourceAttribute.onDelete) sourceAttribute.onDelete = 'CASCADE';
if (!sourceAttribute.onUpdate) sourceAttribute.onUpdate = 'CASCADE';
targetAttribute.references = this.target.getTableName();
targetAttribute.referencesKey = targetKeyField;
targetAttribute.references = {
model: this.target.getTableName(),
key: targetKeyField
};
// But the for target attribute the previously defined option is the priority (since it could've been set by another belongsToMany call)
targetAttribute.onDelete = this.through.model.rawAttributes[this.foreignIdentifier].onDelete || this.options.onDelete;
targetAttribute.onUpdate = this.through.model.rawAttributes[this.foreignIdentifier].onUpdate || this.options.onUpdate;
......
......@@ -26,18 +26,20 @@ module.exports = {
if (primaryKeys.length === 1) {
if (!!source.options.schema) {
newAttribute.references = source.modelManager.sequelize.queryInterface.QueryGenerator.addSchema({
tableName: source.tableName,
options: {
schema: source.options.schema,
schemaDelimiter: source.options.schemaDelimiter
}
});
newAttribute.references = {
model: source.modelManager.sequelize.queryInterface.QueryGenerator.addSchema({
tableName: source.tableName,
options: {
schema: source.options.schema,
schemaDelimiter: source.options.schemaDelimiter
}
})
};
} else {
newAttribute.references = source.tableName;
newAttribute.references = { model: source.tableName };
}
newAttribute.referencesKey = primaryKeys[0];
newAttribute.references.key = primaryKeys[0];
newAttribute.onDelete = options.onDelete;
newAttribute.onUpdate = options.onUpdate;
}
......
......@@ -333,7 +333,7 @@ module.exports = (function() {
}
// handle self referential constraints
if (attribute.Model && attribute.Model.tableName === attribute.references) {
if (attribute.Model && attribute.references && attribute.Model.tableName === attribute.references.model) {
this.sequelize.log('MSSQL does not support self referencial constraints, '
+ 'we will remove it but we recommend restructuring your query');
attribute.onDelete = '';
......@@ -380,10 +380,10 @@ module.exports = (function() {
}
if (attribute.references) {
template += ' REFERENCES ' + this.quoteTable(attribute.references);
template += ' REFERENCES ' + this.quoteTable(attribute.references.model);
if (attribute.referencesKey) {
template += ' (' + this.quoteIdentifier(attribute.referencesKey) + ')';
if (attribute.references.key) {
template += ' (' + this.quoteIdentifier(attribute.references.key) + ')';
} else {
template += ' (' + this.quoteIdentifier('id') + ')';
}
......@@ -410,12 +410,12 @@ module.exports = (function() {
attribute = attributes[key];
if (attribute.references) {
if (existingConstraints.indexOf(attribute.references.toString()) !== -1) {
if (existingConstraints.indexOf(attribute.references.model.toString()) !== -1) {
// no cascading constraints to a table more than once
attribute.onDelete = '';
attribute.onUpdate = '';
} else {
existingConstraints.push(attribute.references.toString());
existingConstraints.push(attribute.references.model.toString());
// NOTE: this really just disables cascading updates for all
// definitions. Can be made more robust to support the
......
......@@ -292,10 +292,10 @@ module.exports = (function() {
}
if (attribute.references) {
template += ' REFERENCES ' + this.quoteTable(attribute.references);
template += ' REFERENCES ' + this.quoteTable(attribute.references.model);
if (attribute.referencesKey) {
template += ' (' + this.quoteIdentifier(attribute.referencesKey) + ')';
if (attribute.references.key) {
template += ' (' + this.quoteIdentifier(attribute.references.key) + ')';
} else {
template += ' (' + this.quoteIdentifier('id') + ')';
}
......
......@@ -511,10 +511,10 @@ module.exports = (function() {
if (attribute.references) {
template += ' REFERENCES <%= referencesTable %> (<%= referencesKey %>)';
replacements.referencesTable = this.quoteTable(attribute.references);
replacements.referencesTable = this.quoteTable(attribute.references.model);
if (attribute.referencesKey) {
replacements.referencesKey = this.quoteIdentifiers(attribute.referencesKey);
if (attribute.references.key) {
replacements.referencesKey = this.quoteIdentifiers(attribute.references.key);
} else {
replacements.referencesKey = this.quoteIdentifier('id');
}
......
......@@ -252,10 +252,10 @@ module.exports = (function() {
if(dataType.references) {
template += ' REFERENCES <%= referencesTable %> (<%= referencesKey %>)';
replacements.referencesTable = this.quoteTable(dataType.references);
replacements.referencesTable = this.quoteTable(dataType.references.model);
if(dataType.referencesKey) {
replacements.referencesKey = this.quoteIdentifier(dataType.referencesKey);
if(dataType.references.key) {
replacements.referencesKey = this.quoteIdentifier(dataType.references.key);
} else {
replacements.referencesKey = this.quoteIdentifier('id');
}
......
......@@ -68,11 +68,12 @@ module.exports = (function() {
for (var attrName in model.rawAttributes) {
if (model.rawAttributes.hasOwnProperty(attrName)) {
if (model.rawAttributes[attrName].references) {
dep = model.rawAttributes[attrName].references;
dep = model.rawAttributes[attrName].references.model;
if (_.isObject(dep)) {
dep = dep.schema + '.' + dep.tableName;
}
deps.push(dep);
}
}
......
......@@ -74,8 +74,8 @@ module.exports = (function() {
}
attribute = this.sequelize.normalizeAttribute(attribute);
if (attribute.references instanceof Model) {
attribute.references = attribute.references.tableName;
if (attribute.references && (attribute.references.model instanceof Model)) {
attribute.references.model = attribute.references.model.tableName;
}
if (attribute.type === undefined) {
......
......@@ -456,8 +456,9 @@ module.exports = (function() {
* @param {String} [attributes.column.field=null] If set, sequelize will map the attribute name to a different name in the database
* @param {Boolean} [attributes.column.autoIncrement=false]
* @param {String} [attributes.column.comment=null]
* @param {String|Model} [attributes.column.references] If this column references another table, provide it here as a Model, or a string
* @param {String} [attributes.column.referencesKey='id'] The column of the foreign table that this column references
* @param {String|Model} [attributes.column.references=null] An object with reference configurations
* @param {String|Model} [attributes.column.references.model] If this column references another table, provide it here as a Model, or a string
* @param {String} [attributes.column.references.key='id'] The column of the foreign table that this column references
* @param {String} [attributes.column.onUpdate] What should happen when the referenced key is updated. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or NO ACTION
* @param {String} [attributes.column.onDelete] What should happen when the referenced key is deleted. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or NO ACTION
* @param {Function} [attributes.column.get] Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying values.
......
......@@ -1885,8 +1885,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
var UserProjects = User.belongsToMany(Project, { foreignKey: { name: 'user_id', defaultValue: 42 }, through: 'UserProjects' });
expect(UserProjects.through.model.rawAttributes.user_id).to.be.ok;
expect(UserProjects.through.model.rawAttributes.user_id.references).to.equal(User.getTableName());
expect(UserProjects.through.model.rawAttributes.user_id.referencesKey).to.equal('uid');
expect(UserProjects.through.model.rawAttributes.user_id.references.model).to.equal(User.getTableName());
expect(UserProjects.through.model.rawAttributes.user_id.references.key).to.equal('uid');
expect(UserProjects.through.model.rawAttributes.user_id.defaultValue).to.equal(42);
});
});
......
......@@ -637,8 +637,8 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() {
expect(Task.rawAttributes.uid).to.be.ok;
expect(Task.rawAttributes.uid.allowNull).to.be.false;
expect(Task.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Task.rawAttributes.uid.referencesKey).to.equal('id');
expect(Task.rawAttributes.uid.references.model).to.equal(User.getTableName());
expect(Task.rawAttributes.uid.references.key).to.equal('id');
});
it('works when taking a column directly from the object', function() {
......@@ -658,8 +658,8 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() {
Profile.belongsTo(User, { foreignKey: Profile.rawAttributes.user_id});
expect(Profile.rawAttributes.user_id).to.be.ok;
expect(Profile.rawAttributes.user_id.references).to.equal(User.getTableName());
expect(Profile.rawAttributes.user_id.referencesKey).to.equal('uid');
expect(Profile.rawAttributes.user_id.references.model).to.equal(User.getTableName());
expect(Profile.rawAttributes.user_id.references.key).to.equal('uid');
expect(Profile.rawAttributes.user_id.allowNull).to.be.false;
});
......
......@@ -907,8 +907,8 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
expect(Task.rawAttributes.uid).to.be.ok;
expect(Task.rawAttributes.uid.allowNull).to.be.false;
expect(Task.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Task.rawAttributes.uid.referencesKey).to.equal('id');
expect(Task.rawAttributes.uid.references.model).to.equal(User.getTableName());
expect(Task.rawAttributes.uid.references.key).to.equal('id');
});
it('works when taking a column directly from the object', function() {
......@@ -928,8 +928,8 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
User.hasMany(Project, { foreignKey: Project.rawAttributes.user_id});
expect(Project.rawAttributes.user_id).to.be.ok;
expect(Project.rawAttributes.user_id.references).to.equal(User.getTableName());
expect(Project.rawAttributes.user_id.referencesKey).to.equal('uid');
expect(Project.rawAttributes.user_id.references.model).to.equal(User.getTableName());
expect(Project.rawAttributes.user_id.references.key).to.equal('uid');
expect(Project.rawAttributes.user_id.defaultValue).to.equal(42);
});
......
......@@ -530,8 +530,8 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
});
expect(Profile.rawAttributes.uid).to.be.ok;
expect(Profile.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Profile.rawAttributes.uid.referencesKey).to.equal('id');
expect(Profile.rawAttributes.uid.references.model).to.equal(User.getTableName());
expect(Profile.rawAttributes.uid.references.key).to.equal('id');
expect(Profile.rawAttributes.uid.allowNull).to.be.false;
// Let's clear it
......@@ -544,8 +544,8 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
});
expect(Profile.rawAttributes.uid).to.be.ok;
expect(Profile.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Profile.rawAttributes.uid.referencesKey).to.equal('id');
expect(Profile.rawAttributes.uid.references.model).to.equal(User.getTableName());
expect(Profile.rawAttributes.uid.references.key).to.equal('id');
expect(Profile.rawAttributes.uid.allowNull).to.be.false;
});
......@@ -566,8 +566,8 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
User.hasOne(Profile, { foreignKey: Profile.rawAttributes.user_id});
expect(Profile.rawAttributes.user_id).to.be.ok;
expect(Profile.rawAttributes.user_id.references).to.equal(User.getTableName());
expect(Profile.rawAttributes.user_id.referencesKey).to.equal('uid');
expect(Profile.rawAttributes.user_id.references.model).to.equal(User.getTableName());
expect(Profile.rawAttributes.user_id.references.key).to.equal('uid');
expect(Profile.rawAttributes.user_id.allowNull).to.be.false;
});
......@@ -589,8 +589,8 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
expect(Project.rawAttributes.userUid).to.be.ok;
expect(Project.rawAttributes.userUid.allowNull).to.be.false;
expect(Project.rawAttributes.userUid.references).to.equal(User.getTableName());
expect(Project.rawAttributes.userUid.referencesKey).to.equal('uid');
expect(Project.rawAttributes.userUid.references.model).to.equal(User.getTableName());
expect(Project.rawAttributes.userUid.references.key).to.equal('uid');
expect(Project.rawAttributes.userUid.defaultValue).to.equal(42);
});
});
......
......@@ -44,23 +44,23 @@ if (Support.dialectIsMySQL()) {
expectation: {id: 'INTEGER UNIQUE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`pk`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, autoIncrement: true, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', allowNull: false, autoIncrement: true, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL auto_increment DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'}
}
],
......
......@@ -58,49 +58,49 @@ if (dialect.match(/^postgres/)) {
expectation: {id: 'INTEGER UNIQUE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}
},
// Variants when quoteIdentifiers is false
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
expectation: {id: 'INTEGER REFERENCES Bar (id)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],
expectation: {id: 'INTEGER REFERENCES Bar (pk)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
}
......
......@@ -54,23 +54,23 @@ if (dialect === 'sqlite') {
expectation: {id: 'INTEGER UNIQUE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`pk`)'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'}
}
],
......
......@@ -1241,8 +1241,10 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
},
UserId: {
type: Sequelize.INTEGER,
references: UserModel,
referencesKey: 'Id'
references: {
model: UserModel,
key: 'Id'
}
},
Name: Sequelize.STRING,
Contact: Sequelize.STRING,
......
......@@ -2183,8 +2183,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
title: Sequelize.STRING,
authorId: {
type: Sequelize.INTEGER,
references: this.Author,
referencesKey: 'id'
references: {
model: this.Author,
key: 'id'
}
}
});
......@@ -2213,8 +2215,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
title: Sequelize.STRING,
authorId: {
type: Sequelize.INTEGER,
references: 'authors',
referencesKey: 'id'
references: {
model: 'authors',
key: 'id'
}
}
});
......@@ -2242,8 +2246,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
title: Sequelize.STRING,
authorId: {
type: Sequelize.INTEGER,
references: '4uth0r5',
referencesKey: 'id'
references: {
model: '4uth0r5',
key: 'id'
}
}
});
......@@ -2284,15 +2290,17 @@ describe(Support.getTestDialectTeaser('Model'), function() {
// jshint ignore:start
var Member = this.sequelize.define('Member', {})
, Profile = this.sequelize.define('Profile', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
references: Member,
referencesKey: 'id',
autoIncrement: false,
comment: 'asdf'
}
});
id: {
type: Sequelize.INTEGER,
primaryKey: true,
references: {
model: Member,
key: 'id'
},
autoIncrement: false,
comment: 'asdf'
}
});
// jshint ignore:end
return this.sequelize.sync({ force: true });
......@@ -2571,8 +2579,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var project = this.sequelize.define('project', {
UserId: {
type: Sequelize.STRING,
references: 'Users',
referencesKey: 'UUID'
references: {
model: 'Users',
key: 'UUID'
}
}
});
......
......@@ -456,8 +456,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({ force: true })
.then(function() {
var attrs = this.Task.tableAttributes;
expect(attrs.user_id.references).to.equal('users');
expect(attrs.user_id.referencesKey).to.equal('userId');
expect(attrs.user_id.references.model).to.equal('users');
expect(attrs.user_id.references.key).to.equal('userId');
}.bind(this));
});
......
......@@ -406,8 +406,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}).bind(this).then(function() {
return this.queryInterface.addColumn('users', 'level_id', {
type: DataTypes.INTEGER,
references: 'level',
referenceKey: 'id',
references: {
model: 'level',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'set null'
}, {logging: log});
......@@ -466,19 +468,25 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
},
admin: {
type: DataTypes.INTEGER,
references: 'users',
referenceKey: 'id'
references: {
model: 'users',
key: 'id'
}
},
operator: {
type: DataTypes.INTEGER,
references: 'users',
referenceKey: 'id',
references: {
model: 'users',
key: 'id'
},
onUpdate: 'cascade'
},
owner: {
type: DataTypes.INTEGER,
references: 'users',
referenceKey: 'id',
references: {
model: 'users',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'set null'
}
......
......@@ -737,7 +737,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
it('returns an error correctly if unable to sync a foreign key referenced model', function() {
this.sequelize.define('Application', {
authorID: { type: Sequelize.BIGINT, allowNull: false, references: 'User', referencesKey: 'id' }
authorID: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'User', key: 'id' } }
});
return this.sequelize.sync().catch(function(error) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!