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 47c040a5
authored
Aug 17, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix through table attributes not working for createAssociation in n:m. Closes #2155
1 parent
1d024baa
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
9 deletions
docs/markdox.js
lib/associations/has-many.js
lib/hooks.js
test/associations/has-many.test.js
docs/markdox.js
View file @
47c040a
...
...
@@ -109,7 +109,7 @@ var options = {
if
(
!
javadoc
.
name
)
{
var
property
=
getTag
(
javadoc
.
raw
.
tags
,
'property'
);
if
(
property
)
{
javadoc
.
name
=
property
.
string
;
javadoc
.
name
=
property
.
types
[
0
]
;
}
}
if
(
javadoc
.
isMixin
)
{
...
...
lib/associations/has-many.js
View file @
47c040a
...
...
@@ -449,21 +449,16 @@ module.exports = (function() {
var
association
=
this
;
obj
[
this
.
accessors
.
create
]
=
function
(
values
,
fieldsOrOptions
)
{
var
instance
=
this
,
options
=
{};
var
instance
=
this
;
if
(
values
===
undefined
)
{
values
=
{};
}
if
((
fieldsOrOptions
||
{}).
transaction
instanceof
Transaction
)
{
options
.
transaction
=
fieldsOrOptions
.
transaction
;
}
if
(
Object
(
association
.
through
)
===
association
.
through
)
{
// Create the related model instance
return
association
.
target
.
create
(
values
,
fieldsOrOptions
).
then
(
function
(
newAssociatedObject
)
{
return
instance
[
association
.
accessors
.
add
](
newAssociatedObject
,
o
ptions
).
return
(
newAssociatedObject
);
return
instance
[
association
.
accessors
.
add
](
newAssociatedObject
,
fieldsOrO
ptions
).
return
(
newAssociatedObject
);
});
}
else
{
values
[
association
.
identifier
]
=
instance
.
get
(
association
.
source
.
primaryKeyAttribute
);
...
...
lib/hooks.js
View file @
47c040a
...
...
@@ -136,6 +136,7 @@ Hooks.hook = function() {
* @param {String} hooktype
* @param {String} [name] Provide a name for the hook function. This serves no purpose, other than the ability to be able to order hooks based on some sort of priority system in the future.
* @param {Function} fn The hook function
*
* @alias hook
*/
Hooks
.
addHook
=
function
(
hookType
,
name
,
fn
)
{
...
...
@@ -196,7 +197,8 @@ Hooks.afterCreate = function(name, fn) {
* A hook that is run before destroying a single instance
* @param {String} name
* @param {Function} fn A callback function that is called with instance, callback(err)
* alias beforeDelete
*
* @alias beforeDelete
*/
Hooks
.
beforeDestroy
=
function
(
name
,
fn
)
{
Hooks
.
addHook
.
call
(
this
,
'beforeDestroy'
,
name
,
fn
);
...
...
@@ -206,6 +208,7 @@ Hooks.beforeDestroy = function(name, fn) {
* A hook that is run after destroying a single instance
* @param {String} name
* @param {Function} fn A callback function that is called with instance, callback(err)
*
* @alias afterDelete
*/
Hooks
.
afterDestroy
=
function
(
name
,
fn
)
{
...
...
test/associations/has-many.test.js
View file @
47c040a
...
...
@@ -1083,6 +1083,34 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
return
this
.
t
.
rollback
();
});
});
it
(
'supports setting through table attributes'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'group'
,
{})
,
UserGroups
=
this
.
sequelize
.
define
(
'user_groups'
,
{
isAdmin
:
Sequelize
.
BOOLEAN
});
User
.
hasMany
(
Group
,
{
through
:
UserGroups
});
Group
.
hasMany
(
User
,
{
through
:
UserGroups
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Group
.
create
({});
}).
then
(
function
(
group
)
{
return
Promise
.
join
(
group
.
createUser
({
id
:
1
},
{
isAdmin
:
true
}),
group
.
createUser
({
id
:
2
},
{
isAdmin
:
false
}),
function
()
{
return
UserGroups
.
findAll
();
}
);
}).
then
(
function
(
userGroups
)
{
expect
(
userGroups
[
0
].
userId
).
to
.
equal
(
1
);
expect
(
userGroups
[
0
].
isAdmin
).
to
.
be
.
ok
;
expect
(
userGroups
[
1
].
userId
).
to
.
equal
(
2
);
expect
(
userGroups
[
1
].
isAdmin
).
not
.
to
.
be
.
ok
;
});
});
});
describe
(
'addAssociations'
,
function
()
{
...
...
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