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 21565c2e
authored
Feb 25, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hotfix for through tables and custom primarykeys
1 parent
cc02a9bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
9 deletions
lib/associations/has-many-double-linked.js
test/associations/has-many.test.js
lib/associations/has-many-double-linked.js
View file @
21565c2
...
@@ -25,16 +25,12 @@ module.exports = (function() {
...
@@ -25,16 +25,12 @@ module.exports = (function() {
//fully qualify
//fully qualify
var
instancePrimaryKeys
=
Object
.
keys
(
self
.
instance
.
daoFactory
.
primaryKeys
)
var
instancePrimaryKeys
=
Object
.
keys
(
self
.
instance
.
daoFactory
.
primaryKeys
)
,
instancePrimaryKey
=
instancePrimaryKeys
.
length
>
0
?
instancePrimaryKeys
[
0
]
:
'id'
,
instancePrimaryKey
=
instancePrimaryKeys
.
length
>
0
?
instancePrimaryKeys
[
0
]
:
'id'
where
[
through
.
tableName
+
"."
+
self
.
association
.
identifier
]
=
self
.
instance
[
instancePrimaryKey
]
var
primaryKeys
=
Object
.
keys
(
through
.
primaryKeys
)
,
foreignKey
=
primaryKeys
.
filter
(
function
(
pk
)
{
return
pk
!=
self
.
association
.
identifier
})[
0
]
,
foreignPrimary
=
Object
.
keys
(
self
.
association
.
target
.
primaryKeys
)
,
foreignPrimary
=
Object
.
keys
(
self
.
association
.
target
.
primaryKeys
)
foreignPrimary
=
foreignPrimary
.
length
===
1
?
foreignPrimary
[
0
]
:
'id'
foreignPrimary
=
foreignPrimary
.
length
===
1
?
foreignPrimary
[
0
]
:
'id'
where
[
through
.
tableName
+
"."
+
foreignKey
]
=
{
join
:
self
.
association
.
target
.
tableName
+
"."
+
foreignPrimary
}
where
[
through
.
tableName
+
"."
+
self
.
association
.
identifier
]
=
self
.
instance
[
instancePrimaryKey
]
where
[
through
.
tableName
+
"."
+
self
.
association
.
foreignIdentifier
]
=
{
join
:
self
.
association
.
target
.
tableName
+
"."
+
foreignPrimary
}
if
(
Object
(
targetAssociation
.
through
)
===
targetAssociation
.
through
)
{
if
(
Object
(
targetAssociation
.
through
)
===
targetAssociation
.
through
)
{
queryOptions
.
hasJoinTableModel
=
true
queryOptions
.
hasJoinTableModel
=
true
...
...
test/associations/has-many.test.js
View file @
21565c2
...
@@ -946,7 +946,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -946,7 +946,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
describe
(
'
join table model
'
,
function
()
{
describe
(
'
through
'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{})
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{})
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{})
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{})
...
@@ -1049,9 +1049,56 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1049,9 +1049,56 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
Worker
.
create
().
done
(
function
(
err
,
worker
)
{
Worker
.
create
({
id
:
1337
}).
done
(
function
(
err
,
worker
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Task
.
create
({
id
:
7331
}).
done
(
function
(
err
,
task
)
{
expect
(
err
).
not
.
to
.
be
.
ok
worker
.
addTask
(
task
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
worker
.
addTask
(
task
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
()
})
})
})
})
})
})
it
(
'should be able to add twice (second call result in UPDATE call) with custom primary keys and without any attributes (and timestamps off) on the through model'
,
function
(
done
)
{
var
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
}
},
{
timestamps
:
false
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
}
},
{
timestamps
:
false
})
,
WorkerTasks
=
this
.
sequelize
.
define
(
'WorkerTasks'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
}
},
{
timestamps
:
false
})
Worker
.
hasMany
(
Task
,
{
through
:
WorkerTasks
})
Task
.
hasMany
(
Worker
,
{
through
:
WorkerTasks
})
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Worker
.
create
({
id
:
1337
}).
done
(
function
(
err
,
worker
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
Task
.
create
().
done
(
function
(
err
,
task
)
{
Task
.
create
(
{
id
:
7331
}
).
done
(
function
(
err
,
task
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
worker
.
addTask
(
task
).
done
(
function
(
err
)
{
worker
.
addTask
(
task
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
...
...
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