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 fa19ed9d
authored
Jan 06, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] correctly identify attributes with field as a JSON attribute on update, fixes #2790
1 parent
a07a9dd8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
17 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/query-generator.js
test/dialects/postgres/dao.test.js
lib/dialects/abstract/query-generator.js
View file @
fa19ed9
...
...
@@ -315,7 +315,7 @@ module.exports = (function() {
}
var
value
=
attrValueHash
[
key
];
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
escape
(
value
,
(
!!
attributes
&&
!!
attributes
[
key
]
?
attributes
[
key
]
:
undefined
)));
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
]
||
undefined
)));
}
var
replacements
=
{
...
...
lib/dialects/postgres/query-generator.js
View file @
fa19ed9
...
...
@@ -896,7 +896,7 @@ module.exports = (function() {
}
else
if
(
field
.
type
===
DataTypes
.
ARRAY
(
DataTypes
.
HSTORE
)){
return
"ARRAY["
+
Utils
.
_
.
map
(
value
,
function
(
v
){
return
"'"
+
hstore
.
stringify
(
v
)
+
"'::hstore"
;}).
join
(
","
)
+
"]::HSTORE[]"
;
}
}
else
if
(
Utils
.
_
.
isObject
(
value
)
&&
field
&&
(
field
.
type
===
DataTypes
.
JSON
))
{
}
else
if
(
Utils
.
_
.
isObject
(
value
)
&&
field
&&
(
field
.
type
===
DataTypes
.
JSON
||
field
.
type
===
DataTypes
.
JSONB
))
{
value
=
JSON
.
stringify
(
value
);
}
...
...
test/dialects/postgres/dao.test.js
View file @
fa19ed9
...
...
@@ -72,37 +72,35 @@ if (dialect.match(/^postgres/)) {
});
});
it
(
'should insert json using a custom field name'
,
function
(
done
)
{
it
(
'should insert json using a custom field name'
,
function
()
{
var
self
=
this
;
this
.
UserFields
=
this
.
sequelize
.
define
(
'UserFields'
,
{
emergency
_contact
:
{
type
:
DataTypes
.
JSON
,
field
:
'something_else
'
}
emergency
Contact
:
{
type
:
DataTypes
.
JSON
,
field
:
'emergy_contact
'
}
});
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
self
.
UserFields
.
create
({
emergency
_c
ontact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
return
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
UserFields
.
create
({
emergency
C
ontact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
}).
then
(
function
(
user
)
{
expect
(
user
.
emergency_contact
.
name
).
to
.
equal
(
'joe'
);
done
();
expect
(
user
.
emergencyContact
.
name
).
to
.
equal
(
'joe'
);
});
});
});
it
(
'should update json using a custom field name'
,
function
(
done
)
{
it
(
'should update json using a custom field name'
,
function
()
{
var
self
=
this
;
this
.
UserFields
=
this
.
sequelize
.
define
(
'UserFields'
,
{
emergency
_contact
:
{
type
:
DataTypes
.
JSON
,
field
:
'something_else
'
}
emergency
Contact
:
{
type
:
DataTypes
.
JSON
,
field
:
'emergy_contact
'
}
});
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
self
.
UserFields
.
create
({
emergency
_c
ontact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
return
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
UserFields
.
create
({
emergency
C
ontact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
}).
then
(
function
(
user
)
{
user
.
emergency
_c
ontact
=
{
name
:
'larry'
};
user
.
emergency
C
ontact
=
{
name
:
'larry'
};
return
user
.
save
();
}).
then
(
function
(
user
)
{
expect
(
user
.
emergency_contact
.
name
).
to
.
equal
(
'larry'
);
done
();
expect
(
user
.
emergencyContact
.
name
).
to
.
equal
(
'larry'
);
});
});
});
...
...
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