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 ebbfd6e4
authored
Oct 15, 2013
by
Rafael Martins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding support for filter through hasMany connector
1 parent
3e29e69f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
lib/dialects/sqlite/query-generator.js
test/associations/multiple-level-filters.test.js
lib/dialects/sqlite/query-generator.js
View file @
ebbfd6e
...
@@ -345,6 +345,7 @@ module.exports = (function() {
...
@@ -345,6 +345,7 @@ module.exports = (function() {
,
attributePart
=
associationParts
.
pop
()
,
attributePart
=
associationParts
.
pop
()
,
self
=
this
,
self
=
this
return
associationParts
.
every
(
function
(
attribute
)
{
return
associationParts
.
every
(
function
(
attribute
)
{
var
association
=
self
.
findAssociation
(
attribute
,
dao
);
var
association
=
self
.
findAssociation
(
attribute
,
dao
);
if
(
!
association
)
return
false
;
if
(
!
association
)
return
false
;
...
@@ -382,6 +383,14 @@ module.exports = (function() {
...
@@ -382,6 +383,14 @@ module.exports = (function() {
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
}
else
if
(
association
.
connectorDAO
){
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
source
.
autoIncrementField
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
+
'.'
+
association
.
foreignIdentifier
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
}
else
{
}
else
{
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
source
.
autoIncrementField
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
source
.
autoIncrementField
)
...
...
test/associations/multiple-level-filters.test.js
View file @
ebbfd6e
...
@@ -137,4 +137,58 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
...
@@ -137,4 +137,58 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
});
});
})
})
})
})
it
(
'can filter through hasMany connector'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
title
:
DataTypes
.
STRING
})
Project
.
hasMany
(
User
);
User
.
hasMany
(
Project
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
bulkCreate
([{
id
:
101
,
username
:
'leia'
},
{
id
:
102
,
username
:
'vader'
}]).
success
(
function
()
{
Project
.
bulkCreate
([{
id
:
201
,
title
:
'republic'
},{
id
:
202
,
title
:
'empire'
}]).
success
(
function
()
{
User
.
find
(
101
).
success
(
function
(
user
){
Project
.
find
(
201
).
success
(
function
(
project
){
user
.
setProjects
([
project
]).
success
(
function
(){
User
.
find
(
102
).
success
(
function
(
user
){
Project
.
find
(
202
).
success
(
function
(
project
){
user
.
setProjects
([
project
]).
success
(
function
(){
User
.
findAll
({
where
:
{
'projects.title'
:
'republic'
}
}).
success
(
function
(
users
){
try
{
expect
(
users
.
length
).
to
.
be
.
equal
(
1
);
expect
(
users
[
0
].
username
).
to
.
be
.
equal
(
'leia'
);
done
();
}
catch
(
e
){
done
(
e
);
}
})
});
});
});
});
});
});
});
});
})
})
})
})
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