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 0f786c88
authored
Jan 04, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1:1 setAssociation should not clobber fields - Adds a returning option to save
1 parent
86ba3b36
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
3 deletions
lib/associations/belongs-to.js
lib/associations/has-one.js
lib/dao.js
lib/dialects/abstract/query-generator.js
test/associations/belongs-to.test.js
lib/associations/belongs-to.js
View file @
0f786c8
...
...
@@ -86,7 +86,11 @@ module.exports = (function() {
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
this
[
self
.
identifier
]
=
associatedObject
?
associatedObject
[
primaryKey
]
:
null
options
=
Utils
.
_
.
extend
({
fields
:
[
self
.
identifier
],
allowNull
:
[
self
.
identifier
]
},
options
)
options
=
Utils
.
_
.
extend
({
fields
:
[
self
.
identifier
],
allowNull
:
[
self
.
identifier
],
association
:
true
},
options
)
// passes the changed field to save, so only that field get updated.
return
this
.
save
(
options
)
...
...
lib/associations/has-one.js
View file @
0f786c8
...
...
@@ -95,7 +95,8 @@ module.exports = (function() {
.
save
(
Utils
.
_
.
extend
({},
options
,
{
fields
:
[
self
.
identifier
],
allowNull
:
[
self
.
identifier
]
allowNull
:
[
self
.
identifier
],
association
:
true
})
)
.
success
(
function
()
{
...
...
lib/dao.js
View file @
0f786c8
...
...
@@ -270,6 +270,14 @@ module.exports = (function() {
options
.
fields
=
this
.
attributes
}
if
(
options
.
returning
===
undefined
)
{
if
(
options
.
association
)
{
options
.
returning
=
false
}
else
{
options
.
returning
=
true
}
}
var
self
=
this
,
values
=
{}
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
updatedAt
,
this
.
__options
.
underscored
)
...
...
lib/dialects/abstract/query-generator.js
View file @
0f786c8
...
...
@@ -179,7 +179,7 @@ module.exports = (function() {
,
values
=
[]
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
if
(
this
.
_dialect
.
supports
[
'RETURNING'
])
{
if
(
this
.
_dialect
.
supports
[
'RETURNING'
]
&&
(
options
.
returning
||
options
.
returning
===
undefined
)
)
{
query
+=
" RETURNING *"
}
...
...
test/associations/belongs-to.test.js
View file @
0f786c8
...
...
@@ -133,6 +133,36 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
})
it
(
'should not clobber atributes'
,
function
(
done
)
{
var
Comment
=
this
.
sequelize
.
define
(
'comment'
,
{
text
:
DataTypes
.
STRING
});
var
Post
=
this
.
sequelize
.
define
(
'post'
,
{
title
:
DataTypes
.
STRING
});
Post
.
hasOne
(
Comment
);
Comment
.
belongsTo
(
Post
);
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
Post
.
create
({
title
:
'Post title'
,
}).
done
(
function
(
err
,
post
)
{
Comment
.
create
({
text
:
'OLD VALUE'
,
}).
done
(
function
(
err
,
comment
)
{
comment
.
setPost
(
post
).
done
(
function
(
err
)
{
expect
(
comment
.
text
).
to
.
equal
(
'UPDATED VALUE'
);
done
()
});
comment
.
text
=
'UPDATED VALUE'
;
});
});
})
})
})
describe
(
"Foreign key constraints"
,
function
()
{
...
...
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