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 56a8bb47
authored
Dec 03, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(include): cover yet another complex nested include case
1 parent
b7610eab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
41 deletions
lib/dialects/abstract/query-generator.js
test/include/findAll.test.js
lib/dialects/abstract/query-generator.js
View file @
56a8bb4
...
@@ -1011,7 +1011,7 @@ module.exports = (function() {
...
@@ -1011,7 +1011,7 @@ module.exports = (function() {
// Filter statement
// Filter statement
// Used by both join and subquery where
// Used by both join and subquery where
if
(
subQuery
&&
!
include
.
subQuery
&&
include
.
parent
.
subQuery
&&
(
include
.
hasParentRequired
||
include
.
hasParentWhere
))
{
if
(
subQuery
&&
!
include
.
subQuery
&&
include
.
parent
.
subQuery
&&
(
include
.
hasParentRequired
||
include
.
hasParentWhere
||
include
.
parent
.
hasIncludeRequired
||
include
.
parent
.
hasIncludeWhere
))
{
joinOn
=
self
.
quoteIdentifier
(
tableLeft
+
'.'
+
attrLeft
);
joinOn
=
self
.
quoteIdentifier
(
tableLeft
+
'.'
+
attrLeft
);
}
else
{
}
else
{
if
(
association
.
associationType
!==
'BelongsTo'
)
{
if
(
association
.
associationType
!==
'BelongsTo'
)
{
...
...
test/include/findAll.test.js
View file @
56a8bb4
...
@@ -235,50 +235,66 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -235,50 +235,66 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
}
}
});
});
it
(
'should work on pretty complicated case'
,
function
()
{
it
(
'should work on a nested set of relations with a where condition in between relations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
SubscriptionForm
=
this
.
sequelize
.
define
(
'SubscriptionForm'
,
{})
,
SubscriptionForm
=
this
.
sequelize
.
define
(
'SubscriptionForm'
,
{})
,
Collection
=
this
.
sequelize
.
define
(
'Collection'
,
{})
,
Collection
=
this
.
sequelize
.
define
(
'Collection'
,
{})
,
Category
=
this
.
sequelize
.
define
(
'Category'
,
{})
,
Category
=
this
.
sequelize
.
define
(
'Category'
,
{})
,
SubCategory
=
this
.
sequelize
.
define
(
'SubCategory'
,
{})
,
SubCategory
=
this
.
sequelize
.
define
(
'SubCategory'
,
{})
,
Capital
=
this
.
sequelize
.
define
(
'Capital'
,
{});
,
Capital
=
this
.
sequelize
.
define
(
'Capital'
,
{});
User
.
hasOne
(
SubscriptionForm
,
{
foreignKey
:
'boundUser'
});
SubscriptionForm
.
belongsTo
(
User
,
{
foreignKey
:
'boundUser'
});
SubscriptionForm
.
hasOne
(
Collection
,
{
foreignKey
:
'boundDesigner'
});
Collection
.
belongsTo
(
SubscriptionForm
,
{
foreignKey
:
'boundDesigner'
});
SubscriptionForm
.
belongsTo
(
Category
,
{
foreignKey
:
'boundCategory'
});
Category
.
hasMany
(
SubscriptionForm
,
{
foreignKey
:
'boundCategory'
});
Capital
.
hasMany
(
Category
,
{
foreignKey
:
'boundCapital'
})
Capital
.
hasMany
(
Category
,
{
foreignKey
:
'boundCapital'
});
SubCategory
.
belongsTo
(
Category
,
{
foreignKey
:
'boundCategory'
})
Category
.
belongsTo
(
Capital
,
{
foreignKey
:
'boundCapital'
});
Category
.
belongsTo
(
Capital
,
{
foreignKey
:
'boundCapital'
})
Category
.
hasMany
(
SubCategory
,
{
foreignKey
:
'boundCategory'
})
Category
.
hasMany
(
SubCategory
,
{
foreignKey
:
'boundCategory'
});
Category
.
hasMany
(
SubscriptionForm
,
{
foreignKey
:
'boundCategory'
})
SubCategory
.
belongsTo
(
Category
,
{
foreignKey
:
'boundCategory'
});
Collection
.
belongsTo
(
SubscriptionForm
,
{
foreignKey
:
'boundDesigner'
})
SubscriptionForm
.
belongsTo
(
User
,
{
foreignKey
:
'boundUser'
})
SubscriptionForm
.
belongsTo
(
Category
,
{
foreignKey
:
'boundCategory'
})
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
SubscriptionForm
.
hasOne
(
Collection
,
{
foreignKey
:
'boundDesigner'
})
User
.
hasOne
(
SubscriptionForm
,
{
foreignKey
:
'boundUser'
})
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(
function
()
{
return
User
.
find
({
return
User
.
find
({
include
:
[{
include
:
[
model
:
SubscriptionForm
,
{
include
:
[{
model
:
SubscriptionForm
,
model
:
Collection
,
include
:
[
where
:
{
{
id
:
0
model
:
Collection
,
}
where
:
{
},
{
id
:
13
model
:
Category
,
}
include
:
[{
},
model
:
SubCategory
{
},
{
model
:
Category
,
model
:
Capital
,
include
:
[
include
:
[{
{
model
:
Category
model
:
SubCategory
}]
},
}]
{
}]
model
:
Capital
,
}]
include
:
[
})
{
})
model
:
Category
}
]
}
]
}
]
}
]
});
});
});
});
it
(
'should accept nested `where` and `limit` at the same time'
,
function
()
{
it
(
'should accept nested `where` and `limit` at the same time'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
DataTypes
.
STRING
title
:
DataTypes
.
STRING
...
...
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