Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit e92577ee
authored
Nov 27, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:sequelize/sequelize
Conflicts: changelog.md
2 parents
4244ac8d
1b54275a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
115 additions
and
55 deletions
changelog.md
docs/articles/getting-started.md
docs/docs/associations.md
docs/docs/instances.md
docs/docs/querying.md
docs/index.md
lib/associations/belongs-to-many.js
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/dialects/abstract/connection-manager.js
lib/model.js
test/unit/associations/dont-modify-options.test.js
changelog.md
View file @
e92577e
# Next
]
# Next
-
[
FIXED
]
Model.aggregate methods now support attributes and where conditions with fields.
[
#4935
](
https://github.com/sequelize/sequelize/issues/4935
)
-
[
FIXED
]
Don't overwrite options.foreignKey in associations
[
#4927
](
https://github.com/sequelize/sequelize/pull/4927
)
# 3.14.1
-
[
FIXED
]
Issue with transaction options leaking and certain queries running outside of the transaction connection.
...
...
docs/articles/getting-started.md
View file @
e92577e
...
...
@@ -53,7 +53,8 @@ sequelize
.
authenticate
()
.
then
(
function
(
err
)
{
console
.
log
(
'Connection has been established successfully.'
);
},
function
(
err
)
{
})
.
catch
(
function
(
err
)
{
console
.
log
(
'Unable to connect to the database:'
,
err
);
});
```
...
...
docs/docs/associations.md
View file @
e92577e
...
...
@@ -510,12 +510,12 @@ Project.create({ /* */ }).then(function(project) {
// check if all associated objects are as expected:
// let's assume we have already a project and two users
project
.
setUsers
([
user1
,
user2
]).
then
(
function
()
{
return
project
.
hasUsers
([
user1
])
.
then
(
function
(
result
)
{
// result would be false
return
project
.
hasUsers
([
user1
,
user2
]).
then
(
function
(
result
)
{
// result would be true
})
})
return
project
.
hasUsers
([
user1
])
;
}).
then
(
function
(
result
)
{
// result would be false
return
project
.
hasUsers
([
user1
,
user2
]);
}).
then
(
function
(
result
)
{
// result would be true
})
```
...
...
docs/docs/instances.md
View file @
e92577e
...
...
@@ -113,10 +113,9 @@ Once you created an object and got a reference to it, you can delete it fr
```
js
Task
.
create
({
title
:
'a task'
}).
then
(
function
(
task
)
{
// now you see me...
task
.
destroy
().
then
(
function
()
{
// now i'm gone :)
})
return
task
.
destroy
();
}).
then
(
function
()
{
// now i'm gone :)
})
```
...
...
@@ -144,9 +143,9 @@ User.bulkCreate([
{
username
:
'foo'
,
isAdmin
:
true
},
{
username
:
'bar'
,
isAdmin
:
false
}
]).
then
(
function
()
{
// Notice: There are no arguments here, as of right now you'll have to...
User
.
findAll
().
then
(
function
(
users
)
{
console
.
log
(
users
)
// ... in order to get the array of user objects
})
return
User
.
findAll
();
}).
then
(
function
(
users
)
{
console
.
log
(
users
)
// ... in order to get the array of user objects
})
```
...
...
@@ -158,15 +157,15 @@ Task.bulkCreate([
{
subject
:
'reading'
,
status
:
'executing'
},
{
subject
:
'programming'
,
status
:
'finished'
}
]).
then
(
function
()
{
Task
.
update
(
{
status
:
'inactive'
}
/* set attributes' value */
,
return
Task
.
update
(
{
status
:
'inactive'
}
,
/* set attributes' value */
,
{
where
:
{
subject
:
'programming'
}}
/* where criteria */
)
.
then
(
function
(
affectedRows
)
{
// affectedRows will be 2
Task
.
findAll
().
then
(
function
(
tasks
)
{
console
.
log
(
tasks
)
// the 'programming' tasks will both have a status of 'inactive'
})
})
)
;
}).
then
(
function
(
affectedRows
)
{
// affectedRows will be 2
return
Task
.
findAll
();
}).
then
(
function
(
tasks
)
{
console
.
log
(
tasks
)
// the 'programming' tasks will both have a status of 'inactive'
})
```
...
...
@@ -178,17 +177,17 @@ Task.bulkCreate([
{
subject
:
'reading'
,
status
:
'executing'
},
{
subject
:
'programming'
,
status
:
'finished'
}
]).
then
(
function
()
{
Task
.
destroy
({
return
Task
.
destroy
({
where
:
{
subject
:
'programming'
},
truncate
:
true
/* this will ignore where and truncate the table instead */
})
.
then
(
function
(
affectedRows
)
{
// affectedRows will be 2
Task
.
findAll
().
then
(
function
(
tasks
)
{
console
.
log
(
tasks
)
// no programming, just reading :(
})
})
})
;
}).
then
(
function
(
affectedRows
)
{
// affectedRows will be 2
return
Task
.
findAll
();
}).
then
(
function
(
tasks
)
{
console
.
log
(
tasks
)
// no programming, just reading :(
})
```
...
...
@@ -294,27 +293,27 @@ First of all you can define a field and the value you want to add to it.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
increment
(
'my-integer-field'
,
{
by
:
2
}).
then
(
/* ... */
)
})
return
user
.
increment
(
'my-integer-field'
,
{
by
:
2
}
)
})
.
then
(
/* ... */
)
```
Second
,
you can define multiple fields and the value you want to add to them
.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
increment
([
'my-integer-field'
,
'my-very-other-field'
],
{
by
:
2
}).
then
(
/* ... */
)
})
return
user
.
increment
([
'my-integer-field'
,
'my-very-other-field'
],
{
by
:
2
}
)
})
.
then
(
/* ... */
)
```
Third
,
you can define an object containing fields and its increment values
.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
increment
({
return
user
.
increment
({
'my-integer-field'
:
2
,
'my-very-other-field'
:
3
})
.
then
(
/* ... */
)
})
})
})
.
then
(
/* ... */
)
```
## Decrementing certain values of an instance
...
...
@@ -325,25 +324,25 @@ First of all you can define a field and the value you want to add to it.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
decrement
(
'my-integer-field'
,
{
by
:
2
}).
then
(
/* ... */
)
})
return
user
.
decrement
(
'my-integer-field'
,
{
by
:
2
}
)
})
.
then
(
/* ... */
)
```
Second
,
you can define multiple fields and the value you want to add to them
.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
decrement
([
'my-integer-field'
,
'my-very-other-field'
],
{
by
:
2
}).
then
(
/* ... */
)
})
return
user
.
decrement
([
'my-integer-field'
,
'my-very-other-field'
],
{
by
:
2
}
)
})
.
then
(
/* ... */
)
```
Third
,
you can define an object containing fields and its decrement values
.
```
js
User
.
findById
(
1
).
then
(
function
(
user
)
{
user
.
decrement
({
return
user
.
decrement
({
'my-integer-field'
:
2
,
'my-very-other-field'
:
3
})
.
then
(
/* ... */
)
})
})
})
.
then
(
/* ... */
)
```
docs/docs/querying.md
View file @
e92577e
...
...
@@ -146,7 +146,7 @@ $col: 'user.organization_id' // = "user"."organization_id", with dialect specifi
{
rank
:
{
$or
:
{
$lt
:
100
,
$lt
:
100
0
,
$eq
:
null
}
}
...
...
docs/index.md
View file @
e92577e
...
...
@@ -24,10 +24,10 @@ sequelize.sync().then(function() {
return
User
.
create
({
username
:
'janedoe'
,
birthday
:
new
Date
(
1980
,
6
,
20
)
})
.
then
(
function
(
jane
)
{
console
.
log
(
jane
.
get
(
{
plain
:
true
}))
}
);
})
;
}).
then
(
function
(
jane
)
{
console
.
log
(
jane
.
get
({
plain
:
true
})
);
});
```
lib/associations/belongs-to-many.js
View file @
e92577e
...
...
@@ -323,8 +323,8 @@ BelongsToMany.prototype.injectAttributes = function() {
,
targetKey
=
this
.
target
.
rawAttributes
[
this
.
target
.
primaryKeyAttribute
]
,
targetKeyType
=
targetKey
.
type
,
targetKeyField
=
targetKey
.
field
||
this
.
target
.
primaryKeyAttribute
,
sourceAttribute
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
type
:
sourceKeyType
})
,
targetAttribute
=
_
.
defaults
(
this
.
otherKeyAttribute
,
{
type
:
targetKeyType
});
,
sourceAttribute
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
sourceKeyType
})
,
targetAttribute
=
_
.
defaults
(
{},
this
.
otherKeyAttribute
,
{
type
:
targetKeyType
});
if
(
this
.
primaryKeyDeleted
===
true
)
{
targetAttribute
.
primaryKey
=
sourceAttribute
.
primaryKey
=
true
;
...
...
lib/associations/belongs-to.js
View file @
e92577e
...
...
@@ -109,7 +109,7 @@ util.inherits(BelongsTo, Association);
BelongsTo
.
prototype
.
injectAttributes
=
function
()
{
var
newAttributes
=
{};
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
this
.
target
.
rawAttributes
[
this
.
targetKey
].
type
,
allowNull
:
true
});
...
...
lib/associations/has-many.js
View file @
e92577e
...
...
@@ -202,7 +202,7 @@ util.inherits(HasMany, Association);
HasMany
.
prototype
.
injectAttributes
=
function
()
{
var
newAttributes
=
{};
var
constraintOptions
=
_
.
clone
(
this
.
options
);
// Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
,
allowNull
:
true
});
...
...
lib/associations/has-one.js
View file @
e92577e
...
...
@@ -103,7 +103,7 @@ HasOne.prototype.injectAttributes = function() {
var
newAttributes
=
{}
,
keyType
=
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
;
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
keyType
,
allowNull
:
true
});
...
...
lib/dialects/abstract/connection-manager.js
View file @
e92577e
...
...
@@ -97,6 +97,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy
:
function
(
connection
)
{
self
.
$disconnect
(
connection
);
return
null
;
},
max
:
config
.
pool
.
max
,
min
:
config
.
pool
.
min
,
...
...
@@ -174,6 +175,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy
:
function
(
connection
)
{
self
.
$disconnect
(
connection
);
return
null
;
},
validate
:
config
.
pool
.
validate
,
max
:
config
.
pool
.
max
,
...
...
@@ -191,6 +193,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy
:
function
(
connection
)
{
self
.
$disconnect
(
connection
);
return
null
;
},
validate
:
config
.
pool
.
validate
,
max
:
config
.
pool
.
max
,
...
...
@@ -221,6 +224,7 @@ ConnectionManager.prototype.getConnection = function(options) {
self
.
versionPromise
=
null
;
self
.
$disconnect
(
connection
);
return
null
;
});
}).
catch
(
function
(
err
)
{
self
.
versionPromise
=
null
;
...
...
lib/model.js
View file @
e92577e
...
...
@@ -2450,6 +2450,7 @@ Model.prototype.update = function(values, options) {
delete
options
.
attributes
;
});
}
return
null
;
}).
then
(
function
()
{
valuesUse
=
values
;
...
...
test/unit/associations/dont-modify-options.test.js
0 → 100644
View file @
e92577e
'use strict'
;
/* jshint -W030 */
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
Sequelize
=
require
(
'../../../index'
);
describe
(
Support
.
getTestDialectTeaser
(
'associations'
),
function
()
{
describe
(
'Test options.foreignKey'
,
function
()
{
beforeEach
(
function
()
{
this
.
A
=
this
.
sequelize
.
define
(
'A'
,
{
id
:
{
type
:
DataTypes
.
CHAR
(
20
),
primaryKey
:
true
}
});
this
.
B
=
this
.
sequelize
.
define
(
'B'
,
{
id
:
{
type
:
Sequelize
.
CHAR
(
20
),
primaryKey
:
true
}
});
this
.
C
=
this
.
sequelize
.
define
(
'C'
,
{});
});
it
(
'should not be overwritten for belongsTo'
,
function
(){
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
this
.
A
.
belongsTo
(
this
.
B
,
reqValidForeignKey
);
this
.
A
.
belongsTo
(
this
.
C
,
reqValidForeignKey
);
expect
(
this
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
this
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for belongsToMany'
,
function
(){
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
},
through
:
'ABBridge'
};
this
.
B
.
belongsToMany
(
this
.
A
,
reqValidForeignKey
);
this
.
A
.
belongsTo
(
this
.
C
,
reqValidForeignKey
);
expect
(
this
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
this
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for hasOne'
,
function
(){
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
this
.
B
.
hasOne
(
this
.
A
,
reqValidForeignKey
);
this
.
A
.
belongsTo
(
this
.
C
,
reqValidForeignKey
);
expect
(
this
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
this
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for hasMany'
,
function
(){
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
this
.
B
.
hasMany
(
this
.
A
,
reqValidForeignKey
);
this
.
A
.
belongsTo
(
this
.
C
,
reqValidForeignKey
);
expect
(
this
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
this
.
C
.
attributes
.
id
.
type
);
});
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment