Skip to content

Commit

Permalink
More changelog entries to the correct place, fix the remaining test
Browse files Browse the repository at this point in the history
  • Loading branch information
janmeier committed Jul 11, 2014
1 parent 2210ce4 commit 51035b1
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 201 deletions.
16 changes: 9 additions & 7 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ Notice: All 1.7.x changes are present in 2.0.x aswell

# Next
- [FEATURE] Added to option of setting a timezone offset in the sequelize constructor (`timezone` option). This timezone is used when initializing a connection (using `SET TIME ZONE` or equivalent), and when converting a timestamp string from the DB to a JS date with mysql (postgres stores the timezone, so for postgres we rely on what's in the DB).
- [FEATURE] Allow setting plural and singular name on the model (`options.name` in `sequelize.define`) and in associations (`options.as`) to circumvent issues with weird pluralization.
- [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`

#### Backwards compatability changes
- We are using a new inflection library, which should make pluralization and singularization in general more robust. However, a couple of pluralizations have changed as a result:
+ Person is now pluralized as people instead of persons
- Accesors for models with underscored names are no longer camel cased automatically. For example, if you have a model with name `my_model`, and `my_other_model.hasMany(my_model)`, the getter will now be `instance_of_my_model.getMy_model` instead of `.getMyModel`.
- Removed support for setting sequelize.language. If your model names are not in english, use the name option provided by `sequelize.name` to defined singular and plural forms for your model.
- Model names are now used more verbatim in associations. This means that if you have a model named `Task` (plural T), or an association specifying `{ as: 'Task' }`, the tasks will be returned as `relatedModel.Tasks` instead of `relatedModel.tasks`. For more information and how to mitigate this, see https://github.com/sequelize/sequelize/wiki/Upgrading-to-2.0#inflection-replaces-lingo-and-changes-to-naming-conventions

# v2.0.0-dev12
- [FEATURE] You can now return a promise to a hook rather than use a callback
Expand All @@ -24,9 +33,6 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Use the provided name for a unique index if one is given, instead of concating the column names together [#1944](https://github.com/sequelize/sequelize/issues/1944)
- [BUG] Create a composite primary key for doubled linked self reference [#1891](https://github.com/sequelize/sequelize/issues/1891)
- [INTERNALS] `bulkDeleteQuery` was removed from the MySQL / abstract query generator, since it was never used internally. Please use `deleteQuery` instead.
- [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`


#### Backwards compatability changes
- Sequelize now returns promises instead of its custom event emitter from most calls. This affects methods that return multiple values (like `findOrCreate` or `findOrInitialize`). If your current callbacks do not accept the 2nd success parameter you might be seeing an array as the first param. Either use `.spread()` for these methods or add another argument to your callback: `.success(instance)` -> `.success(instance, created)`.
Expand All @@ -37,10 +43,6 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- `sequelize.transaction()` now returns a promise rather than a instance of Sequelize.Transaction
- `bulkCreate`, `bulkUpdate` and `bulkDestroy` (and aliases) now take both a `hooks` and an `individualHooks` option, `hooks` defines whether or not to run the main hooks, and `individualHooks` defines whether to run hooks for each instance affected.
- It is no longer possible to disable pooling, disable pooling will just result in a 1/1 pool.
- We are using a new inflection library, which should make pluralization and singularization in general more robust. However, a couple of pluralizations have changed as a result:
+ Person is now pluralized as people instead of persons
- Accesors for models with underscored names are no longer camel cased automatically. For example, if you have a model with name `my_model`, and `my_other_model` hasMany `my_model`, the getter will now be `getMy_model` instead of `getMyModel`.
- Removed support for setting sequelize.language. If your model names are not in english, use the name option provided by `sequelize.name` to defined singular and plural forms for your model.

# v2.0.0-dev11
### Caution: This release contains many changes and is highly experimental
Expand Down
1 change: 0 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,3 @@ Utils.col.prototype.toString = function(queryGenerator, parentModel) {
Utils.CustomEventEmitter = require(__dirname + '/emitters/custom-event-emitter');
Utils.Promise = require(__dirname + '/promise');
Utils.QueryChainer = require(__dirname + '/query-chainer');
Utils.Lingo = require('lingo');
117 changes: 117 additions & 0 deletions test/associations/alias.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"use strict";

/* jshint camelcase: false, expr: true */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + "/../../lib/data-types")
, Sequelize = require('../../index')
, Promise = Sequelize.Promise
, assert = require('assert');

chai.config.includeStack = true;

describe(Support.getTestDialectTeaser("Alias"), function() {
it('should uppercase the first letter in alias getter, but not in eager loading', function () {
var User = this.sequelize.define('user', {})
, Task = this.sequelize.define('task', {});

User.hasMany(Task, { as: 'assignments', foreignKey: 'userId' });
Task.belongsTo(User, { as: 'owner', foreignKey: 'userId' });

return this.sequelize.sync({ force: true }).then(function () {
return Promise.all([
User.create({ id: 1 }),
Task.create({ id: 1, userId: 1 })
]);
}).spread(function (user, task) {
expect(user.getAssignments).to.be.ok;
expect(task.getOwner).to.be.ok;
}).then(function () {
return Promise.all([
User.find({ where: { id: 1 }, include: [{model: Task, as: 'assignments'}] }),
Task.find({ where: { id: 1 }, include: [{model: User, as: 'owner'}] }),
]);
}).spread(function (user, task) {
expect(user.assignments).to.be.ok;
expect(task.owner).to.be.ok;
});
});

it('shouldnt touch the passed alias', function () {
var User = this.sequelize.define('user', {})
, Task = this.sequelize.define('task', {});

User.hasMany(Task, { as: 'ASSIGNMENTS', foreignKey: 'userId' });
Task.belongsTo(User, { as: 'OWNER', foreignKey: 'userId' });

return this.sequelize.sync({ force: true }).then(function () {
return User.create({ id: 1 });
}).then(function (user){
expect(user.getASSIGNMENTS).to.be.ok;

return Task.create({ id: 1, userId: 1 });
}).then(function (task) {
expect(task.getOWNER).to.be.ok;

return Promise.all([
User.find({ where: { id: 1 }, include: [{model: Task, as: 'ASSIGNMENTS'}] }),
Task.find({ where: { id: 1 }, include: [{model: User, as: 'OWNER'}] }),
]);
}).spread(function (user, task) {
expect(user.ASSIGNMENTS).to.be.ok;
expect(task.OWNER).to.be.ok;
});
});

it('should allow me to pass my own plural and singular forms to hasMany', function () {
var User = this.sequelize.define('user', {})
, Task = this.sequelize.define('task', {});

User.hasMany(Task, { as: { singular: 'task', plural: 'taskz'} });

return this.sequelize.sync({ force: true }).then(function () {
return Promise.all([
User.create({ id: 1 }),
]);
}).spread(function (user, task) {
expect(user.getTaskz).to.be.ok;
expect(user.addTask).to.be.ok;
expect(user.addTaskz).to.be.ok;
}).then(function () {
return Promise.all([
User.find({ where: { id: 1 }, include: [{model: Task, as: 'taskz'}] }),
]);
}).spread(function (user, task) {
expect(user.taskz).to.be.ok;
});
});

it('should allow me to define plural and singular forms on the model', function () {
var User = this.sequelize.define('user', {})
, Task = this.sequelize.define('task', {}, {
name: {
singular: 'assignment',
plural: 'assignments'
}
});

User.hasMany(Task);

return this.sequelize.sync({ force: true }).then(function () {
return Promise.all([
User.create({ id: 1 }),
]);
}).spread(function (user, task) {
expect(user.getAssignments).to.be.ok;
expect(user.addAssignment).to.be.ok;
expect(user.addAssignments).to.be.ok;
}).then(function () {
return Promise.all([
User.find({ where: { id: 1 }, include: [Task] }),
]);
}).spread(function (user, task) {
expect(user.assignments).to.be.ok;
});
});
});
8 changes: 4 additions & 4 deletions test/dao-factory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var product = Product.build({
id: 1,
title: 'Chair',
tags: [
Tags: [
{id: 1, name: 'Alpha'},
{id: 2, name: 'Beta'}
],
user: {
User: {
id: 1,
first_name: 'Mick',
last_name: 'Hansen'
Expand Down Expand Up @@ -527,8 +527,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
]
}, {
include: [
{model: User, as: 'Followers'},
{model: Tag, as: 'Categories'}
{model: User, as: 'followers'},
{model: Tag, as: 'categories'}
]
})

Expand Down
8 changes: 4 additions & 4 deletions test/dao.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,14 +1226,14 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
self.User.findAll({include: [ { model: self.Project, as: 'Projects' } ]}).success(function(users) {
var _user = users[0]

expect(_user.projects).to.exist
expect(JSON.parse(JSON.stringify(_user)).projects).to.exist
expect(_user.Projects).to.exist
expect(JSON.parse(JSON.stringify(_user)).Projects).to.exist

self.Project.findAll({include: [ { model: self.User, as: 'LovelyUser' } ]}).success(function(projects) {
var _project = projects[0]

expect(_project.lovelyUser).to.exist
expect(JSON.parse(JSON.stringify(_project)).lovelyUser).to.exist
expect(_project.LovelyUser).to.exist
expect(JSON.parse(JSON.stringify(_project)).LovelyUser).to.exist

done()
})
Expand Down
42 changes: 21 additions & 21 deletions test/include.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]
}).done(function (err, task) {
expect(err).not.to.be.ok
expect(task.user).to.be.ok
expect(task.group).to.be.ok
expect(task.User).to.be.ok
expect(task.Group).to.be.ok
done()
})
})
Expand Down Expand Up @@ -187,7 +187,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}).done(function (err, group) {
expect(err).not.to.be.ok
expect(group.User).to.be.ok
expect(group.User.task).to.be.ok
expect(group.User.Task).to.be.ok
done()
})
})
Expand Down Expand Up @@ -240,7 +240,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect(user.Tasks).to.be.ok
expect(user.Tasks.length).to.equal(4)

user.tasks.forEach(function (task) {
user.Tasks.forEach(function (task) {
expect(task.Project).to.be.ok
})

Expand Down Expand Up @@ -295,8 +295,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}).done(function (err, worker) {
expect(err).not.to.be.ok
expect(worker.Project).to.be.ok
expect(worker.Project.tasks).to.be.ok
expect(worker.Project.tasks.length).to.equal(4)
expect(worker.Project.Tasks).to.be.ok
expect(worker.Project.Tasks.length).to.equal(4)

done()
})
Expand Down Expand Up @@ -373,10 +373,10 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect(err).not.to.be.ok

expect(user.Products.length).to.equal(4)
expect(user.Products[0].tags.length).to.equal(2)
expect(user.Products[1].tags.length).to.equal(1)
expect(user.Products[2].tags.length).to.equal(3)
expect(user.Products[3].tags.length).to.equal(0)
expect(user.Products[0].Tags.length).to.equal(2)
expect(user.Products[1].Tags.length).to.equal(1)
expect(user.Products[2].Tags.length).to.equal(3)
expect(user.Products[3].Tags.length).to.equal(0)
done()
})
})
Expand Down Expand Up @@ -516,20 +516,20 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}).done(function (err, user) {
user.Memberships.sort(sortById)
expect(user.Memberships.length).to.equal(2)
expect(user.Memberships[0].group.name).to.equal('Developers')
expect(user.Memberships[0].rank.canRemove).to.equal(1)
expect(user.Memberships[1].group.name).to.equal('Designers')
expect(user.Memberships[1].rank.canRemove).to.equal(0)
expect(user.Memberships[0].Group.name).to.equal('Developers')
expect(user.Memberships[0].Rank.canRemove).to.equal(1)
expect(user.Memberships[1].Group.name).to.equal('Designers')
expect(user.Memberships[1].Rank.canRemove).to.equal(0)

user.Products.sort(sortById)
expect(user.Products.length).to.equal(2)
expect(user.Products[0].tags.length).to.equal(2)
expect(user.Products[1].tags.length).to.equal(1)
expect(user.Products[0].category).to.be.ok
expect(user.Products[1].category).not.to.be.ok
expect(user.Products[0].Tags.length).to.equal(2)
expect(user.Products[1].Tags.length).to.equal(1)
expect(user.Products[0].Category).to.be.ok
expect(user.Products[1].Category).not.to.be.ok

expect(user.Products[0].prices.length).to.equal(2)
expect(user.Products[1].prices.length).to.equal(4)
expect(user.Products[0].Prices.length).to.equal(2)
expect(user.Products[1].Prices.length).to.equal(4)

done()
})
Expand Down Expand Up @@ -566,7 +566,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect(tasks[0].title).to.equal('FooBar')
expect(tasks[0].Project.title).to.equal('BarFoo');

expect(_.omit(tasks[0].get(), 'project')).to.deep.equal({ title: 'FooBar' })
expect(_.omit(tasks[0].get(), 'Project')).to.deep.equal({ title: 'FooBar' })
expect(tasks[0].Project.get()).to.deep.equal({ title: 'BarFoo'})

done()
Expand Down
27 changes: 14 additions & 13 deletions test/include/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, Sequelize = require(__dirname + '/../../index')
, DataTypes = require(__dirname + "/../../lib/data-types")
, datetime = require('chai-datetime')
, async = require('async');
Expand Down Expand Up @@ -52,10 +53,10 @@ describe(Support.getTestDialectTeaser("Include"), function () {
});

it("should still pull the main record when an included model is not required and has where restrictions without matches", function () {
var A = this.sequelize.define('A', {
var A = this.sequelize.define('a', {
name: DataTypes.STRING(40)
})
, B = this.sequelize.define('B', {
, B = this.sequelize.define('b', {
name: DataTypes.STRING(40)
});

Expand Down Expand Up @@ -84,16 +85,16 @@ describe(Support.getTestDialectTeaser("Include"), function () {
});

it('should support many levels of belongsTo (with a lower level having a where)', function (done) {
var A = this.sequelize.define('A', {})
, B = this.sequelize.define('B', {})
, C = this.sequelize.define('C', {})
, D = this.sequelize.define('D', {})
, E = this.sequelize.define('E', {})
, F = this.sequelize.define('F', {})
, G = this.sequelize.define('G', {
var A = this.sequelize.define('a', {})
, B = this.sequelize.define('b', {})
, C = this.sequelize.define('c', {})
, D = this.sequelize.define('d', {})
, E = this.sequelize.define('e', {})
, F = this.sequelize.define('f', {})
, G = this.sequelize.define('g', {
name: DataTypes.STRING
})
, H = this.sequelize.define('H', {
, H = this.sequelize.define('h', {
name: DataTypes.STRING
});

Expand Down Expand Up @@ -126,12 +127,12 @@ describe(Support.getTestDialectTeaser("Include"), function () {
async.eachSeries(singles, function (model, callback) {
var values = {};

if (model.name === 'G') {
if (model.name === 'g') {
values.name = 'yolo';
}
model.create(values).done(function (err, instance) {
if (previousInstance) {
previousInstance["set"+model.name](instance).done(function () {
previousInstance["set"+Sequelize.Utils.uppercaseFirst(model.name)](instance).done(function () {
previousInstance = instance;
callback();
});
Expand Down Expand Up @@ -174,4 +175,4 @@ describe(Support.getTestDialectTeaser("Include"), function () {
});
});
});
});
});
Loading

0 comments on commit 51035b1

Please sign in to comment.