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 df42db65
authored
Feb 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 1:M selfAssociations with aliases
1 parent
a31b5d28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
lib/associations/has-many.js
test/associations/has-many.test.js
lib/associations/has-many.js
View file @
df42db6
...
...
@@ -19,7 +19,7 @@ module.exports = (function() {
this
.
sequelize
=
source
.
daoFactoryManager
.
sequelize
this
.
through
=
options
.
through
this
.
isMultiAssociation
=
true
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
===
this
.
target
.
tableName
)
this
.
isSelfAssociation
=
this
.
source
===
this
.
target
this
.
doubleLinked
=
false
this
.
combinedTableName
=
Utils
.
combineTableNames
(
this
.
source
.
tableName
,
...
...
@@ -136,7 +136,7 @@ module.exports = (function() {
// is there already a single sided association between the source and the target?
// or is the association on the model itself?
if
((
this
.
isSelfAssociation
&&
this
.
through
)
||
doubleLinked
)
{
if
((
this
.
isSelfAssociation
&&
Object
(
this
.
through
)
===
this
.
through
)
||
doubleLinked
)
{
// remove the obsolete association identifier from the source
if
(
this
.
isSelfAssociation
)
{
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
,
this
.
options
.
underscored
)
...
...
test/associations/has-many.test.js
View file @
df42db6
...
...
@@ -518,7 +518,17 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
// end optimization using bulk create, destroy and update
describe
(
'selfAssociations'
,
function
()
{
it
(
'should work'
,
function
(
done
)
{
it
(
'should work with alias'
,
function
(
done
)
{
var
Person
=
this
.
sequelize
.
define
(
'Group'
,
{})
Person
.
hasMany
(
Person
,
{
as
:
'Children'
});
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
()
})
})
it
(
'should work with through'
,
function
(
done
)
{
var
Group
=
this
.
sequelize
.
define
(
'Group'
,
{})
Group
.
hasMany
(
Group
,
{
through
:
'groups_outsourcing_companies'
,
as
:
'OutsourcingCompanies'
});
...
...
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