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 de9c66a3
authored
Apr 09, 2020
by
Ben Leith
Committed by
GitHub
Apr 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(belongs-to-many): allow creation of paranoid join tables (#12088)
1 parent
d16de58f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
2 deletions
lib/associations/belongs-to-many.js
test/integration/associations/belongs-to-many.test.js
types/lib/associations/belongs-to-many.d.ts
types/test/model.ts
lib/associations/belongs-to-many.js
View file @
de9c66a
...
@@ -145,7 +145,7 @@ class BelongsToMany extends Association {
...
@@ -145,7 +145,7 @@ class BelongsToMany extends Association {
this
.
through
.
model
=
this
.
sequelize
.
define
(
this
.
through
.
model
,
{},
Object
.
assign
(
this
.
options
,
{
this
.
through
.
model
=
this
.
sequelize
.
define
(
this
.
through
.
model
,
{},
Object
.
assign
(
this
.
options
,
{
tableName
:
this
.
through
.
model
,
tableName
:
this
.
through
.
model
,
indexes
:
[],
//we don't want indexes here (as referenced in #2416)
indexes
:
[],
//we don't want indexes here (as referenced in #2416)
paranoid
:
false
,
// A paranoid join table does not make sense
paranoid
:
this
.
through
.
paranoid
?
this
.
through
.
paranoid
:
false
,
// Default to non-paranoid join (referenced in #11991)
validate
:
{}
// Don't propagate model-level validations
validate
:
{}
// Don't propagate model-level validations
}));
}));
}
else
{
}
else
{
...
...
test/integration/associations/belongs-to-many.test.js
View file @
de9c66a
...
@@ -2285,6 +2285,36 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -2285,6 +2285,36 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect
(
association
.
through
.
model
.
options
.
paranoid
).
not
.
to
.
be
.
ok
;
expect
(
association
.
through
.
model
.
options
.
paranoid
).
not
.
to
.
be
.
ok
;
});
});
});
});
it
(
'should allow creation of a paranoid join table'
,
()
=>
{
const
paranoidSequelize
=
Support
.
createSequelizeInstance
({
define
:
{
paranoid
:
true
}
}),
ParanoidUser
=
paranoidSequelize
.
define
(
'ParanoidUser'
,
{}),
ParanoidTask
=
paranoidSequelize
.
define
(
'ParanoidTask'
,
{});
ParanoidUser
.
belongsToMany
(
ParanoidTask
,
{
through
:
{
model
:
'UserTasks'
,
paranoid
:
true
}
});
ParanoidTask
.
belongsToMany
(
ParanoidUser
,
{
through
:
{
model
:
'UserTasks'
,
paranoid
:
true
}
});
expect
(
ParanoidUser
.
options
.
paranoid
).
to
.
be
.
ok
;
expect
(
ParanoidTask
.
options
.
paranoid
).
to
.
be
.
ok
;
_
.
forEach
(
ParanoidUser
.
associations
,
association
=>
{
expect
(
association
.
through
.
model
.
options
.
paranoid
).
to
.
be
.
ok
;
});
});
});
});
describe
(
'foreign keys'
,
()
=>
{
describe
(
'foreign keys'
,
()
=>
{
...
...
types/lib/associations/belongs-to-many.d.ts
View file @
de9c66a
...
@@ -21,8 +21,15 @@ import { Association, AssociationScope, ForeignKeyOptions, ManyToManyOptions, Mu
...
@@ -21,8 +21,15 @@ import { Association, AssociationScope, ForeignKeyOptions, ManyToManyOptions, Mu
export
interface
ThroughOptions
{
export
interface
ThroughOptions
{
/**
/**
* The model used to join both sides of the N:M association.
* The model used to join both sides of the N:M association.
* Can be a string if you want the model to be generated by sequelize.
*/
*/
model
:
typeof
Model
;
model
:
typeof
Model
|
string
;
/**
* If true the generated join table will be paranoid
* @default false
*/
paranoid
?:
boolean
;
/**
/**
* A key/value set that will be used for association create and find defaults on the through model.
* A key/value set that will be used for association create and find defaults on the through model.
...
...
types/test/model.ts
View file @
de9c66a
...
@@ -115,3 +115,24 @@ const someInstance = new SomeModel()
...
@@ -115,3 +115,24 @@ const someInstance = new SomeModel()
someInstance
.
getOthers
({
someInstance
.
getOthers
({
joinTableAttributes
:
{
include
:
[
'id'
]
}
joinTableAttributes
:
{
include
:
[
'id'
]
}
})
})
/**
* Test for through options in creating a BelongsToMany association
*/
class
Film
extends
Model
{}
class
Actor
extends
Model
{}
Film
.
belongsToMany
(
Actor
,
{
through
:
{
model
:
'FilmActors'
,
paranoid
:
true
}
})
Actor
.
belongsToMany
(
Film
,
{
through
:
{
model
:
'FilmActors'
,
paranoid
:
true
}
})
\ No newline at end of file
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