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 acce21d4
authored
Sep 06, 2016
by
Jan Aagaard Meier
Committed by
Mick Hansen
Sep 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(btm): Expose belongs to many getter similar to other associations (#6552)
1 parent
2ae4d9a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
47 deletions
lib/associations/belongs-to-many.js
lib/associations/belongs-to-many.js
View file @
acce21d
...
@@ -421,65 +421,70 @@ class BelongsToMany extends Association {
...
@@ -421,65 +421,70 @@ class BelongsToMany extends Association {
return
this
;
return
this
;
}
}
injectGetter
(
obj
)
{
get
(
instance
,
options
)
{
const
association
=
this
;
options
=
Utils
.
cloneDeep
(
options
)
||
{}
;
obj
[
this
.
accessors
.
get
]
=
function
(
options
)
{
const
association
=
this
;
options
=
Utils
.
cloneDeep
(
options
)
||
{};
const
through
=
association
.
through
;
let
scopeWhere
;
let
throughWhere
;
const
through
=
association
.
through
;
if
(
association
.
scope
)
{
let
scopeWhere
;
scopeWhere
=
_
.
clone
(
association
.
scope
)
;
let
throughWhere
;
}
if
(
association
.
scope
)
{
options
.
where
=
{
scopeWhere
=
_
.
clone
(
association
.
scope
);
$and
:
[
}
scopeWhere
,
options
.
where
]
};
options
.
where
=
{
if
(
Object
(
through
.
model
)
===
through
.
model
)
{
$and
:
[
throughWhere
=
{};
scopeWhere
,
throughWhere
[
association
.
foreignKey
]
=
instance
.
get
(
association
.
source
.
primaryKeyAttribute
);
options
.
where
]
};
if
(
Object
(
through
.
model
)
===
through
.
model
)
{
if
(
through
.
scope
)
{
throughWhere
=
{}
;
_
.
assign
(
throughWhere
,
through
.
scope
)
;
throughWhere
[
association
.
foreignKey
]
=
this
.
get
(
association
.
source
.
primaryKeyAttribute
);
}
if
(
through
.
scope
)
{
//If a user pass a where on the options through options, make an "and" with the current throughWhere
_
.
assign
(
throughWhere
,
through
.
scope
);
if
(
options
.
through
&&
options
.
through
.
where
)
{
}
throughWhere
=
{
$and
:
[
throughWhere
,
options
.
through
.
where
]
};
}
//If a user pass a where on the options through options, make an "and" with the current throughWhere
options
.
include
=
options
.
include
||
[];
if
(
options
.
through
&&
options
.
through
.
where
)
{
options
.
include
.
push
({
throughWhere
=
{
association
:
association
.
oneFromTarget
,
$and
:
[
throughWhere
,
options
.
through
.
where
]
attributes
:
options
.
joinTableAttributes
,
};
required
:
true
,
}
where
:
throughWhere
});
}
options
.
include
=
options
.
include
||
[];
let
model
=
association
.
target
;
options
.
include
.
push
({
if
(
options
.
hasOwnProperty
(
'scope'
))
{
association
:
association
.
oneFromTarget
,
if
(
!
options
.
scope
)
{
attributes
:
options
.
joinTableAttributes
,
model
=
model
.
unscoped
();
required
:
true
,
}
else
{
where
:
throughWhere
model
=
model
.
scope
(
options
.
scope
);
});
}
}
}
let
model
=
association
.
target
;
if
(
options
.
hasOwnProperty
(
'schema'
))
{
if
(
options
.
hasOwnProperty
(
'scope'
))
{
model
=
model
.
schema
(
options
.
schema
,
options
.
schemaDelimiter
);
if
(
!
options
.
scope
)
{
}
model
=
model
.
unscoped
();
}
else
{
model
=
model
.
scope
(
options
.
scope
);
}
}
if
(
options
.
hasOwnProperty
(
'schema'
))
{
return
model
.
findAll
(
options
);
model
=
model
.
schema
(
options
.
schema
,
options
.
schemaDelimiter
);
}
}
return
model
.
findAll
(
options
);
injectGetter
(
obj
)
{
const
association
=
this
;
obj
[
this
.
accessors
.
get
]
=
function
(
options
)
{
return
association
.
get
(
this
,
options
);
};
};
obj
[
this
.
accessors
.
count
]
=
function
(
options
)
{
obj
[
this
.
accessors
.
count
]
=
function
(
options
)
{
...
...
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