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 63d4aaa3
authored
Jul 24, 2018
by
u9r52sld
Committed by
Sushant
Jul 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(json): access included data with attributes (#9662)
1 parent
c0038718
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
lib/dialects/abstract/query-generator.js
test/integration/json.test.js
lib/dialects/abstract/query-generator.js
View file @
63d4aaa
...
@@ -1496,6 +1496,10 @@ class QueryGenerator {
...
@@ -1496,6 +1496,10 @@ class QueryGenerator {
let
prefix
;
let
prefix
;
if
(
verbatim
===
true
)
{
if
(
verbatim
===
true
)
{
prefix
=
attr
;
prefix
=
attr
;
}
else
if
(
/#>>|->>/
.
test
(
attr
))
{
prefix
=
`(
${
this
.
quoteIdentifier
(
includeAs
.
internalAs
)}
.
${
attr
.
replace
(
/
\(
|
\)
/g
,
''
)}
)`
;
}
else
if
(
/json_extract/
.
test
(
attr
))
{
prefix
=
`json_extract(
${
this
.
quoteIdentifier
(
includeAs
.
internalAs
)}
.
${
attr
.
replace
(
/
\(
|
\)
|json_extract/g
,
''
)}
)`
;
}
else
{
}
else
{
prefix
=
`
${
this
.
quoteIdentifier
(
includeAs
.
internalAs
)}
.
${
this
.
quoteIdentifier
(
attr
)}
`
;
prefix
=
`
${
this
.
quoteIdentifier
(
includeAs
.
internalAs
)}
.
${
this
.
quoteIdentifier
(
attr
)}
`
;
}
}
...
...
test/integration/json.test.js
View file @
63d4aaa
...
@@ -17,6 +17,9 @@ describe('model', () => {
...
@@ -17,6 +17,9 @@ describe('model', () => {
emergency_contact
:
DataTypes
.
JSON
,
emergency_contact
:
DataTypes
.
JSON
,
emergencyContact
:
DataTypes
.
JSON
emergencyContact
:
DataTypes
.
JSON
});
});
this
.
Order
=
this
.
sequelize
.
define
(
'Order'
);
this
.
Order
.
belongsTo
(
this
.
User
);
return
this
.
sequelize
.
sync
({
force
:
true
});
return
this
.
sequelize
.
sync
({
force
:
true
});
});
});
...
@@ -255,6 +258,65 @@ describe('model', () => {
...
@@ -255,6 +258,65 @@ describe('model', () => {
});
});
});
});
}
}
it
(
'should be able retrieve json value with nested include'
,
function
()
{
return
this
.
User
.
create
({
emergency_contact
:
{
name
:
'kate'
}
}).
then
(
user
=>
{
return
this
.
Order
.
create
({
UserId
:
user
.
id
});
}).
then
(()
=>
{
return
this
.
Order
.
findAll
({
attributes
:
[
'id'
],
include
:
[{
model
:
this
.
User
,
attributes
:
[
[
this
.
sequelize
.
json
(
'emergency_contact.name'
),
'katesName'
]
]
}]
});
}).
then
(
orders
=>
{
expect
(
orders
[
0
].
User
.
getDataValue
(
'katesName'
)).
to
.
equal
(
'kate'
);
});
});
});
}
if
(
current
.
dialect
.
supports
.
JSONB
)
{
describe
(
'jsonb'
,
()
=>
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
emergency_contact
:
DataTypes
.
JSONB
,
});
this
.
Order
=
this
.
sequelize
.
define
(
'Order'
);
this
.
Order
.
belongsTo
(
this
.
User
);
return
this
.
sequelize
.
sync
({
force
:
true
});
});
it
(
'should be able retrieve json value with nested include'
,
function
()
{
return
this
.
User
.
create
({
emergency_contact
:
{
name
:
'kate'
}
}).
then
(
user
=>
{
return
this
.
Order
.
create
({
UserId
:
user
.
id
});
}).
then
(()
=>
{
return
this
.
Order
.
findAll
({
attributes
:
[
'id'
],
include
:
[{
model
:
this
.
User
,
attributes
:
[
[
this
.
sequelize
.
json
(
'emergency_contact.name'
),
'katesName'
]
]
}]
});
}).
then
(
orders
=>
{
expect
(
orders
[
0
].
User
.
getDataValue
(
'katesName'
)).
to
.
equal
(
'kate'
);
});
});
});
});
}
}
});
});
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