Skip to content

Commit b7fa54b

Browse files
Ruben Bridgewatermickhansen
authored andcommitted
Remove callee and fix a bunch of tests
1 parent feacd0a commit b7fa54b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+490
-462
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Sequelize is a promise-based Node.js/io.js ORM for Postgres, MySQL, MariaDB, SQL
1414

1515
From 3.0.0 and up Sequelize will follow SEMVER.
1616

17-
[Upgrading to 2.0](https://github.com/sequelize/sequelize/wiki/Upgrading-to-2.0)
17+
## Backwards compatibility changes
18+
19+
3.0.0 cleans up a lot of deprecated code, making it easier for us to develop and maintain features in the future. This implies that most of the changes in 3.0.0 are breaking changes! Please read the changelog for 3.0.0 carefully.
20+
[Upgrading to 3.0](https://github.com/sequelize/sequelize/wiki/Upgrading-to-3.0).
21+
We highly recommend to use 3.0 as it also includes security related fixes that can't be backported to either 2.0 or 1.7.
22+
23+
If you still use 1.7 please read our guide [Upgrading to 2.0](https://github.com/sequelize/sequelize/wiki/Upgrading-to-2.0) plus the changelog up to now. Version 2.1 also contained new breaking changes.
1824

1925
## Features
2026

changelog.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22

33
3.0.0 cleans up a lot of deprecated code, making it easier for us to develop and maintain features in the future.
44

5-
- [ADDED] findById/findByPrimary takes a single value as argument representing the primary key to find.
5+
- [ADDED] findById / findByPrimary takes a single value as argument representing the primary key to find.
66
- [CHANGED] belongsToMany relations MUST now be given a `through` argument.
7-
- [CHANGED] findOne/findAll/findAndCount/findOrCreate now only takes a single options argument instead of a options, queryOptions argument. So set transaction, raw, etc on the first options argument.
7+
- [CHANGED] findOne / findAll / findAndCount / findOrCreate now only takes a single options argument instead of a options and queryOptions argument. So set transaction, raw, etc on the first options argument.
88
- [CHANGED] The accessor for belongsToMany relationships is now either the `as` argument or the target model name pluralized.
99
- [REMOVED] N:M relationships can no longer be represented by 2 x hasMany
10-
- [REMOVED] Model.create/Model.bulkCreate no longer takes an array of fields as its second argument, use `options.fields` instead.
11-
- [REMOVED] Query Chainer has been remved
10+
- [REMOVED] Model.create / Model.bulkCreate / Instance.save no longer takes an array of fields as its second argument, use `options.fields` instead.
11+
- [REMOVED] Query Chainer has been removed
1212
- [REMOVED] Migrations have been removed, use umzug instead
1313
- [REMOVED] Model.findAllJoin has been removed
14-
- [REMOVED] sequelize.query now only takes `sql, callee, options` as arguments, the 4th argument `replacements` has been removed and should be set via `options.replacements` instead.
14+
- [REMOVED] sequelize.query now only takes `sql and options` as arguments, the second and fourth argument `callee` and `replacements` have been removed and should be set via `options.instance` / `options.model` and `options.replacements` instead.
1515
- [REMOVED] `instance.isDirty` has been removed, use `instance.changed()` instead
1616
- [REMOVED] `instance.values` has been removed, use `instance.get()` instead
1717
- [REMOVED] `instance.primaryKeyValues` has been removed.
18+
- [REMOVED] `instance.identifiers` has been removed, use `instance.where()` instead
1819
- [REMOVED] `instance.isDeleted` has been removed, simply check the timestamp with `get('deletedAt')` instead
1920
- [REMOVED] `instance.increment/decrement` now longer takes a number as it's second argument.
20-
- [REMOVED/SECURITY] findOne no longer takes a string/integer/binary argument to represent a primaryKey. Use findById instead
21+
- [REMOVED/SECURITY] findOne no longer takes a string / integer / binary argument to represent a primaryKey. Use findById instead
2122
- [REMOVED/SECURITY] `where: "raw query"` is no longer legal, you must now explicitely use `where: ["raw query", [replacements]]`
2223
- [BUG] Fix showIndexQuery so appropriate indexes are returned when a schema is used
2324
- [BUG] Fix addIndexQuery error when the model has a schema
2425
- [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
2526
- [BUG] Fix bulkCreate: do not insert NULL for undefined values [3729](https://github.com/sequelize/sequelize/pull/3729)
2627
- [BUG] Fix trying to roll back a comitted transaction if an error occured while comitting resulting in an unhandled rejection [3726](https://github.com/sequelize/sequelize/pull/3726)
2728
- [BUG] Fix regression in beforeUpdate hook where `instance.changed()` would always be false [3727](https://github.com/sequelize/sequelize/pull/3727)
29+
- [BUG] Fix trying to roll back a comitted transaction if an error occured while comitting
2830

2931
#### Backwards compatibility changes
3032
- Most of the changes in 3.0.0 are BC breaking, read the changelog for 3.0.0 carefully.

docs/docs/associations.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A simple example would be a **User** being part of a team **Team** with the fore
1010
```js
1111
var Player = this.sequelize.define('Player', {/* attributes */})
1212
, Team = this.sequelize.define('Team', {/* attributes */});
13-
13+
1414
Player.belongsTo(Team); // Will add a TeamId attribute to Player to hold the primary key value for Team
1515
```
1616

@@ -23,7 +23,7 @@ The default casing is `camelCase` however if the source model is configured with
2323
```js
2424
var User = this.sequelize.define('User', {/* attributes */})
2525
, Company = this.sequelize.define('Company', {/* attributes */});
26-
26+
2727
User.belongsTo(Company); // Will add CompanyId to user
2828

2929
var User = this.sequelize.define('User', {/* attributes */}, {underscored: true})
@@ -33,7 +33,7 @@ var User = this.sequelize.define('User', {/* attributes */}, {underscored: true}
3333
primaryKey: true
3434
}
3535
});
36-
36+
3737
User.belongsTo(Company); // Will add company_uuid to user
3838
```
3939

@@ -42,7 +42,7 @@ In cases where `as` has been defined it will be used in place of the target mode
4242
```js
4343
var User = this.sequelize.define('User', {/* attributes */})
4444
, UserRole = this.sequelize.define('UserRole', {/* attributes */});
45-
45+
4646
User.belongsTo(UserRole, {as: 'Role'}); // Adds RoleId to user rather than UserRoleId
4747
```
4848

@@ -52,7 +52,7 @@ When the foreign key option is used, Sequelize will use it as-is:
5252
```js
5353
var User = this.sequelize.define('User', {/* attributes */})
5454
, Company = this.sequelize.define('Company', {/* attributes */});
55-
55+
5656
User.belongsTo(Company, {foreignKey: 'fk_company'}); // Adds fk_company to User
5757
```
5858

@@ -73,9 +73,9 @@ Project.hasOne(User)
7373
Furthermore, Project.prototype will gain the methods getUser and setUser according
7474
to the first parameter passed to define. If you have underscore style
7575
enabled, the added attribute will be project_id instead of ProjectId.
76-
76+
7777
The foreign key will be placed on the users table.
78-
78+
7979
You can also define the foreign key, e.g. if you already have an existing
8080
database and want to work on it:
8181
*/
@@ -131,7 +131,7 @@ But we want more! Let's define it the other way around by creating a many to man
131131
## Belongs-To-Many associations
132132

133133
Belongs-To-Many associations are used to connect sources with multiple targets. Furthermore the targets can also have connections to multiple sources.
134-
134+
135135
```js
136136
Project.belongsToMany(User, {through: 'UserProject'});
137137
User.belongsToMany(Project, {through: 'UserProject'});
@@ -144,13 +144,13 @@ Defining `through` is required. Sequelize would previously attempt to autogenera
144144
This will add methods `getUsers`, `setUsers`, `addUsers` to `Project`, and `getProjects`, `setProjects` and `addProject` to `User`.
145145

146146
Sometimes you may want to rename your models when using them in associations. Let's define users as workers and projects as tasks by using the alias (`as`) option:
147-
```js
147+
```js
148148
User.belongsToMany(Project, { as: 'Tasks', through: 'worker_tasks' })
149149
Project.belongsToMany(User, { as: 'Workers', through: 'worker_tasks' })
150150
```
151151

152152
Of course you can also define self references with belongsToMany:
153-
153+
154154
```js
155155
Person.belongsToMany(Person, { as: 'Children', through: 'PersonChildren' })
156156
// This will create the table PersonChildren which stores the ids of the objects.
@@ -170,13 +170,13 @@ Project.belongsToMany(User, { through: UserProjects })
170170
```
171171

172172
To add a new project to a user and set it's status, you pass an extra object to the setter, which contains the attributes for the join table
173-
173+
174174
```js
175175
user.addProject(project, { status: 'started' })
176176
```
177177

178178
By default the code above will add ProjectId and UserId to the UserProjects table, and _remove any previously defined primary key attribute_ - the table will be uniquely identified by the combination of the keys of the two tables, and there is no reason to have other PK columns. To enforce a primary key on the `UserProjects` model you can add it manually.
179-
179+
180180
```js
181181
UserProjects = sequelize.define('UserProjects', {
182182
id: {
@@ -322,8 +322,8 @@ Post.hasMany(Tag, {
322322
Post.getPendingTags();
323323
```
324324
```sql
325-
SELECT `tag`.* INNER JOIN `item_tags` AS `item_tag`
326-
ON `tag`.`id` = `item_tag`.`tagId`
325+
SELECT `tag`.* INNER JOIN `item_tags` AS `item_tag`
326+
ON `tag`.`id` = `item_tag`.`tagId`
327327
AND `item_tag`.`taggable_id` = 42
328328
AND `item_tag`.`taggable` = 'post'
329329
WHERE (`tag`.`status` = 'pending');
@@ -343,7 +343,7 @@ User.belongsToMany(Project, { as: { singular: 'task', plural: 'tasks' }})
343343
```
344344

345345
If you know that a model will always use the same alias in associations, you can provide it when creating the model
346-
346+
347347
```js
348348
var Project = sequelize.define('project', attributes, {
349349
name: {
@@ -360,7 +360,7 @@ This will add the functions `add/set/get Tasks` to user instances.
360360
## Associating objects
361361

362362
Because Sequelize is doing a lot of magic, you have to call `Sequelize.sync` after setting the associations! Doing so will allow you the following:
363-
363+
364364
```js
365365
Project.belongsToMany(Task)
366366
Task.belongsToMany(Project)
@@ -393,7 +393,7 @@ project.getTasks({attributes: ['title']}).then(function(tasks) {
393393
```
394394

395395
To remove created associations you can just call the set method without a specific id:
396-
396+
397397
```js
398398
// remove the association with task1
399399
project.setTasks([task2]).then(function(associatedTasks) {
@@ -433,7 +433,7 @@ Task#setAuthor(anAuthor)
433433
```
434434

435435
Adding associations to a relation with a custom join table can be done in two ways (continuing with the associations defined in the previous chapter):
436-
436+
437437
```js
438438
// Either by adding a property with the name of the join table model to the object, before creating the association
439439
project.UserProjects = {
@@ -471,15 +471,15 @@ u.getProjects().then(function(projects) {
471471
```
472472

473473
If you only need some of the attributes from the join table, you can provide an array with the attributes you want:
474-
474+
475475
```js
476476
// This will select only name from the Projects table, and only status from the UserProjects table
477477
user.getProjects({ attributes: ['name'], joinTableAttributes: ['status']})
478478
```
479479

480480
## Check associations
481481
You can also check if an object is already associated with another one (N:M only). Here is how you'd do it:
482-
482+
483483
```js
484484
// check if an object is one of associated ones:
485485
Project.create({ /* */ }).then(function(project) {
@@ -520,64 +520,64 @@ Task.belongsTo(User)
520520
```
521521

522522
Will generate the following SQL:
523-
523+
524524
```sql
525525
CREATE TABLE IF NOT EXISTS `User` (
526-
`id` INTEGER PRIMARY KEY,
526+
`id` INTEGER PRIMARY KEY,
527527
`username` VARCHAR(255)
528528
);
529-
529+
530530
CREATE TABLE IF NOT EXISTS `Task` (
531-
`id` INTEGER PRIMARY KEY,
532-
`title` VARCHAR(255),
531+
`id` INTEGER PRIMARY KEY,
532+
`title` VARCHAR(255),
533533
`user_id` INTEGER REFERENCES `User` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
534534
);
535535
```
536536

537-
The relation between task and user injects the `user_id` foreign key on tasks, and marks it as a reference to the `User` table. By default `user_id` will be set to `NULL` if the referenced user is deleted, and updated if the id of the user id updated. These options can be overridden by passing `onUpdate` and `onDelete` options to the association calls. The validation options are `RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL`.
537+
The relation between task and user injects the `user_id` foreign key on tasks, and marks it as a reference to the `User` table. By default `user_id` will be set to `NULL` if the referenced user is deleted, and updated if the id of the user id updated. These options can be overridden by passing `onUpdate` and `onDelete` options to the association calls. The validation options are `RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL`.
538538

539539
For 1:1 and 1:m associations the default option is `SET NULL` for deletion, and `CASCADE` for updates. For n:m, the default for both is `CASCADE`. This means, that if you delete or update a row from one side of an n:m association, all the rows in the join table referencing that row will also be deleted or updated.
540540

541541
Adding constraints between tables means that tables must be created in the database in a certain order, when using `sequelize.sync`. If Task has a reference to User, the User table must be created before the Task table can be created. This can sometimes lead to circular references, where sequelize cannot find an order in which to sync. Imagine a scenario of documents and versions. A document can have multiple versions, and for convenience, a document has an reference to it's current version.
542-
542+
543543
```js
544544
var Document = this.sequelize.define('Document', {
545545
author: Sequelize.STRING
546546
})
547547
, Version = this.sequelize.define('Version', {
548548
timestamp: Sequelize.DATE
549549
})
550-
550+
551551
Document.hasMany(Version) // This adds document_id to version
552552
Document.belongsTo(Version, { as: 'Current', foreignKey: 'current_version_id'}) // This adds current_version_id to document
553553
```
554554

555555
However, the code above will result in the following error: `Cyclic dependency found. 'Document' is dependent of itself. Dependency Chain: Document -> Version => Document`. In order to alleviate that, we can pass `constraints: false` to one of the associations:
556-
556+
557557
```js
558558
Document.hasMany(Version)
559559
Document.belongsTo(Version, { as: 'Current', foreignKey: 'current_version_id', constraints: false})
560560
```
561561

562562
Which will allow us to sync the tables correctly:
563-
563+
564564
```sql
565565
CREATE TABLE IF NOT EXISTS `Document` (
566-
`id` INTEGER PRIMARY KEY,
567-
`author` VARCHAR(255),
566+
`id` INTEGER PRIMARY KEY,
567+
`author` VARCHAR(255),
568568
`current_version_id` INTEGER
569569
);
570570
CREATE TABLE IF NOT EXISTS `Version` (
571-
`id` INTEGER PRIMARY KEY,
572-
`timestamp` DATETIME,
571+
`id` INTEGER PRIMARY KEY,
572+
`timestamp` DATETIME,
573573
`document_id` INTEGER REFERENCES `Document` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
574574
);
575575
```
576576

577577
### Enforcing a foreign key reference without constraints
578578

579579
Some times you may want to reference another table, without adding any constraints, or associations. In that case you can manually add the reference attributes to your schema definition, and mark the relations between them.
580-
580+
581581
```js
582582
var Series, Trainer, Video
583583

docs/docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ var sequelize = new Sequelize('connectionUri', {
8080
var User = sequelize.define('user', {}); // timestamps is false by default
8181
var Post = sequelize.define('user', {}, {
8282
timestamps: true // timestamps will now be true
83-
});
83+
});
8484
```

0 commit comments

Comments
 (0)