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 53566b28
authored
Jan 04, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
should be possible to extend the on clause with a where option on a hasMany incl…
…ude with a through model
1 parent
644cb30c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
lib/dialects/abstract/query-generator.js
test/include.test.js
lib/dialects/abstract/query-generator.js
View file @
53566b2
...
@@ -529,6 +529,10 @@ module.exports = (function() {
...
@@ -529,6 +529,10 @@ module.exports = (function() {
joinQueryItem
+=
joinType
+
self
.
quoteIdentifier
(
table
)
+
" AS "
+
self
.
quoteIdentifier
(
as
)
+
" ON "
joinQueryItem
+=
joinType
+
self
.
quoteIdentifier
(
table
)
+
" AS "
+
self
.
quoteIdentifier
(
as
)
+
" ON "
joinQueryItem
+=
self
.
quoteIdentifier
(
tableTarget
)
+
"."
+
self
.
quoteIdentifier
(
attrTarget
)
+
" = "
joinQueryItem
+=
self
.
quoteIdentifier
(
tableTarget
)
+
"."
+
self
.
quoteIdentifier
(
attrTarget
)
+
" = "
joinQueryItem
+=
self
.
quoteIdentifier
(
throughAs
)
+
"."
+
self
.
quoteIdentifier
(
identTarget
)
joinQueryItem
+=
self
.
quoteIdentifier
(
throughAs
)
+
"."
+
self
.
quoteIdentifier
(
identTarget
)
if
(
include
.
where
)
{
joinQueryItem
+=
" AND "
+
self
.
getWhereConditions
(
include
.
where
,
as
,
include
.
daoFactory
,
options
)
}
}
else
{
}
else
{
var
primaryKeysLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
Object
.
keys
(
association
.
target
.
primaryKeys
)
:
Object
.
keys
(
include
.
association
.
source
.
primaryKeys
))
var
primaryKeysLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
Object
.
keys
(
association
.
target
.
primaryKeys
)
:
Object
.
keys
(
include
.
association
.
source
.
primaryKeys
))
,
tableLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
as
:
parentTable
)
,
tableLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
as
:
parentTable
)
...
...
test/include.test.js
View file @
53566b2
...
@@ -1098,6 +1098,73 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -1098,6 +1098,73 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
})
})
it
(
'should be possible to extend the on clause with a where option on a hasMany include with a through model'
,
function
(
done
)
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
DataTypes
.
STRING
})
,
Tag
=
this
.
sequelize
.
define
(
'Tag'
,
{
name
:
DataTypes
.
STRING
})
,
ProductTag
=
this
.
sequelize
.
define
(
'ProductTag'
,
{
priority
:
DataTypes
.
INTEGER
})
Product
.
hasMany
(
Tag
,
{
through
:
ProductTag
})
Tag
.
hasMany
(
Product
,
{
through
:
ProductTag
})
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
async
.
auto
({
products
:
function
(
callback
)
{
Product
.
bulkCreate
([
{
title
:
'Chair'
},
{
title
:
'Desk'
},
{
title
:
'Dress'
}
]).
done
(
function
()
{
Product
.
findAll
().
done
(
callback
)
})
},
tags
:
function
(
callback
)
{
Tag
.
bulkCreate
([
{
name
:
'A'
},
{
name
:
'B'
},
{
name
:
'C'
}
]).
done
(
function
()
{
Tag
.
findAll
().
done
(
callback
)
})
},
productTags
:
[
'products'
,
'tags'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
()
chainer
.
add
(
results
.
products
[
0
].
addTag
(
results
.
tags
[
0
],
{
priority
:
1
}))
chainer
.
add
(
results
.
products
[
0
].
addTag
(
results
.
tags
[
1
],
{
priority
:
2
}))
chainer
.
add
(
results
.
products
[
1
].
addTag
(
results
.
tags
[
1
],
{
priority
:
1
}))
chainer
.
add
(
results
.
products
[
2
].
addTag
(
results
.
tags
[
0
],
{
priority
:
3
}))
chainer
.
add
(
results
.
products
[
2
].
addTag
(
results
.
tags
[
1
],
{
priority
:
1
}))
chainer
.
add
(
results
.
products
[
2
].
addTag
(
results
.
tags
[
2
],
{
priority
:
2
}))
chainer
.
run
().
done
(
callback
)
}]
},
function
(
err
,
results
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Product
.
findAll
({
include
:
[
{
model
:
Tag
,
where
:
{
name
:
'C'
}}
]
}).
done
(
function
(
err
,
products
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
products
.
length
).
to
.
equal
(
1
)
expect
(
products
[
0
].
tags
.
length
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
describe
(
'findAndCountAll'
,
function
()
{
describe
(
'findAndCountAll'
,
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