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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
lib/dialects/sqlite/query-generator.js
test/associations/multiple-level-filters.test.js
lib/dialects/sqlite/query-generator.js
View file @
ebbfd6e
...
...
@@ -65,15 +65,15 @@ module.exports = (function() {
dataType
=
dataType
.
replace
(
/BIGINT/
,
'INTEGER'
)
}
// SQLite thinks that certain modifiers should come before the length declaration,
// whereas other dialects want them after, see http://www.sqlite.org/lang_createtable.html.
// SQLite thinks that certain modifiers should come before the length declaration,
// whereas other dialects want them after, see http://www.sqlite.org/lang_createtable.html.
// Start by finding the index of the last of the modifiers
[
'UNSIGNED'
,
'BINARY'
,
'ZEROFILL'
].
forEach
(
function
(
modifier
)
{
var
tmpIndex
=
dataType
.
indexOf
(
modifier
)
if
(
tmpIndex
>
modifierLastIndex
)
{
modifierLastIndex
=
tmpIndex
+
modifier
.
length
modifierLastIndex
=
tmpIndex
+
modifier
.
length
}
})
if
(
modifierLastIndex
)
{
...
...
@@ -345,6 +345,7 @@ module.exports = (function() {
,
attributePart
=
associationParts
.
pop
()
,
self
=
this
return
associationParts
.
every
(
function
(
attribute
)
{
var
association
=
self
.
findAssociation
(
attribute
,
dao
);
if
(
!
association
)
return
false
;
...
...
@@ -382,6 +383,14 @@ module.exports = (function() {
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
identifier
)
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
{
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
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() {
});
})
})
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