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 2d21c8c0
authored
Sep 03, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the assocname instead of the tablename for many to many tables
1 parent
07959e96
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
9 deletions
lib/sequelize/Helper.js
lib/sequelize/SequelizeTable.js
test/SequelizeHelperTest.js
test/SequelizeTableTest.js
lib/sequelize/Helper.js
View file @
2d21c8c
...
...
@@ -14,8 +14,11 @@ exports.Helper = function(Sequelize) {
},
SQL
:
{
manyToManyTableName
:
function
(
t1
,
t2
)
{
return
[
t1
.
tableName
,
t2
.
tableName
].
sort
().
join
(
""
)
manyToManyTableName
:
function
(
name1
,
name2
)
{
var
_name1
=
name1
[
0
].
toUpperCase
()
+
name1
.
replace
(
/^./
,
""
)
var
_name2
=
name2
[
0
].
toUpperCase
()
+
name2
.
replace
(
/^./
,
""
)
return
[
_name1
,
_name2
].
sort
().
join
(
""
)
},
asTableIdentifier
:
function
(
name
)
{
...
...
lib/sequelize/SequelizeTable.js
View file @
2d21c8c
...
...
@@ -72,7 +72,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
var
_attributes
=
{}
_attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
_attributes
[
association
.
table
.
identifier
]
=
Sequelize
.
INTEGER
sequelize
.
define
(
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
table
,
association
.
tabl
e
),
_attributes
)
sequelize
.
define
(
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
table
.
tableName
,
association
.
nam
e
),
_attributes
)
}
else
{
// one to many relation
association
.
table
.
attributes
[
table
.
identifier
]
=
{
type
:
Sequelize
.
INTEGER
}
...
...
@@ -159,7 +159,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
// don't check inside of method to increase performance
if
(
_table
.
isCrossAssociatedWith
(
table
))
{
table
.
prototype
[
assocName
]
=
function
(
callback
)
{
var
Association
=
sequelize
.
tables
[
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
_table
,
tabl
e
)].
klass
var
Association
=
sequelize
.
tables
[
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
assocName
,
table
.
tableNam
e
)].
klass
var
whereConditions
=
[
table
.
identifier
,
this
.
id
].
join
(
"="
)
Association
.
findAll
({
where
:
whereConditions
},
function
(
result
)
{
if
(
result
.
length
>
0
)
{
...
...
@@ -173,7 +173,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
}
table
.
prototype
[
Sequelize
.
Helper
.
SQL
.
addPrefix
(
'set'
,
assocName
)]
=
function
(
objects
,
callback
)
{
var
self
=
this
var
Association
=
sequelize
.
tables
[
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
_table
,
tabl
e
)].
klass
var
Association
=
sequelize
.
tables
[
Sequelize
.
Helper
.
SQL
.
manyToManyTableName
(
assocName
,
table
.
tableNam
e
)].
klass
var
currentAssociations
=
null
var
objectIds
=
Sequelize
.
Helper
.
Array
.
map
(
objects
,
function
(
obj
)
{
return
obj
.
id
})
...
...
test/SequelizeHelperTest.js
View file @
2d21c8c
...
...
@@ -13,8 +13,8 @@ module.exports = {
},
'SQL: manyToManyTableName'
:
function
(
assert
)
{
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
{
tableName
:
'foo'
},
{
tableName
:
'bar'
}),
'barf
oo'
)
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
{
tableName
:
'bar'
},
{
tableName
:
'foo'
}),
'barf
oo'
)
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
'foo'
,
'bar'
),
'BarF
oo'
)
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
'bar'
,
'foo'
),
'BarF
oo'
)
},
'SQL: asTableIdentifier'
:
function
(
assert
)
{
assert
.
equal
(
h
.
SQL
.
asTableIdentifier
(
'Users'
),
'userId'
)
...
...
test/SequelizeTableTest.js
View file @
2d21c8c
...
...
@@ -51,8 +51,8 @@ module.exports = {
'prepareAssociations hasMany'
:
function
(
assert
)
{
var
ManyToManyPart1
=
s
.
define
(
'ManyToManyPart1'
,
{})
var
ManyToManyPart2
=
s
.
define
(
'ManyToManyPart2'
,
{})
ManyToManyPart1
.
hasMany
(
'manyToManyPart
1
'
,
ManyToManyPart2
)
ManyToManyPart2
.
hasMany
(
'manyToManyPart1'
,
ManyToManyPart1
)
ManyToManyPart1
.
hasMany
(
'manyToManyPart
2s
'
,
ManyToManyPart2
)
ManyToManyPart2
.
hasMany
(
'manyToManyPart1
s
'
,
ManyToManyPart1
)
ManyToManyPart1
.
prepareAssociations
()
ManyToManyPart2
.
prepareAssociations
()
...
...
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