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 c6df537d
authored
Jun 08, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug(assoc:BTM) Fix for plural and singular as in belongsToMany.Closes #3796
1 parent
114970a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
17 deletions
lib/associations/belongs-to-many.js
test/unit/associations/belongs-to-many.test.js
lib/associations/belongs-to-many.js
View file @
c6df537
...
@@ -22,6 +22,24 @@ var BelongsToMany = function(source, target, options) {
...
@@ -22,6 +22,24 @@ var BelongsToMany = function(source, target, options) {
this
.
isSelfAssociation
=
this
.
source
===
this
.
target
;
this
.
isSelfAssociation
=
this
.
source
===
this
.
target
;
this
.
doubleLinked
=
false
;
this
.
doubleLinked
=
false
;
this
.
as
=
this
.
options
.
as
;
this
.
as
=
this
.
options
.
as
;
if
(
this
.
as
)
{
this
.
isAliased
=
true
;
if
(
Utils
.
_
.
isPlainObject
(
this
.
as
))
{
this
.
options
.
name
=
this
.
as
;
this
.
as
=
this
.
as
.
plural
;
}
else
{
this
.
options
.
name
=
{
plural
:
this
.
as
,
singular
:
Utils
.
singularize
(
this
.
as
)
};
}
}
else
{
this
.
as
=
this
.
target
.
options
.
name
.
plural
;
this
.
options
.
name
=
this
.
target
.
options
.
name
;
}
this
.
combinedTableName
=
Utils
.
combineTableNames
(
this
.
combinedTableName
=
Utils
.
combineTableNames
(
this
.
source
.
tableName
,
this
.
source
.
tableName
,
this
.
isSelfAssociation
?
(
this
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
this
.
isSelfAssociation
?
(
this
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
...
@@ -137,23 +155,6 @@ var BelongsToMany = function(source, target, options) {
...
@@ -137,23 +155,6 @@ var BelongsToMany = function(source, target, options) {
this
.
options
.
tableName
=
this
.
combinedName
=
(
this
.
through
.
model
===
Object
(
this
.
through
.
model
)
?
this
.
through
.
model
.
tableName
:
this
.
through
.
model
);
this
.
options
.
tableName
=
this
.
combinedName
=
(
this
.
through
.
model
===
Object
(
this
.
through
.
model
)
?
this
.
through
.
model
.
tableName
:
this
.
through
.
model
);
if
(
this
.
as
)
{
this
.
isAliased
=
true
;
if
(
Utils
.
_
.
isPlainObject
(
this
.
as
))
{
this
.
options
.
name
=
this
.
as
;
this
.
as
=
this
.
as
.
plural
;
}
else
{
this
.
options
.
name
=
{
plural
:
this
.
as
,
singular
:
Utils
.
singularize
(
this
.
as
)
};
}
}
else
{
this
.
as
=
this
.
target
.
options
.
name
.
plural
;
this
.
options
.
name
=
this
.
target
.
options
.
name
;
}
this
.
associationAccessor
=
this
.
as
;
this
.
associationAccessor
=
this
.
as
;
// Get singular and plural names, trying to uppercase the first letter, unless the model forbids it
// Get singular and plural names, trying to uppercase the first letter, unless the model forbids it
...
...
test/unit/associations/belongs-to-many.test.js
0 → 100644
View file @
c6df537
'use strict'
;
/* jshint -W030 */
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
current
=
Support
.
sequelize
;
describe
(
Support
.
getTestDialectTeaser
(
'Associations'
),
function
()
{
describe
(
'belongsToMany'
,
function
()
{
it
(
'works with singular and plural name for self-associations'
,
function
()
{
// Models taken from https://github.com/sequelize/sequelize/issues/3796
var
Service
=
current
.
define
(
'service'
,
{})
,
Instance
=
Service
.
Instance
;
Service
.
belongsToMany
(
Service
,
{
through
:
'Supplements'
,
as
:
'supplements'
});
Service
.
belongsToMany
(
Service
,
{
through
:
'Supplements'
,
as
:
{
singular
:
'supplemented'
,
plural
:
'supplemented'
}});
expect
(
Instance
.
prototype
).
to
.
have
.
property
(
'getSupplements'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
to
.
have
.
property
(
'addSupplement'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
to
.
have
.
property
(
'addSupplements'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
to
.
have
.
property
(
'getSupplemented'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
not
.
to
.
have
.
property
(
'getSupplementeds'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
to
.
have
.
property
(
'addSupplemented'
).
which
.
is
.
a
.
function
;
expect
(
Instance
.
prototype
).
not
.
to
.
have
.
property
(
'addSupplementeds'
).
which
.
is
.
a
.
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