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 bfa9d65c
authored
Jul 29, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
many-to-many associations are almost working
1 parent
8d8b491a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
11 deletions
src/SequelizeTable.js
src/SequelizeTable.js
View file @
bfa9d65
...
...
@@ -22,10 +22,12 @@ SequelizeTable = function(sequelize, tableName, attributes) {
attributes
:
attributes
,
tableName
:
tableName
,
isCrossAssociatedWith
:
function
(
_t
able
)
{
isCrossAssociatedWith
:
function
(
associatedT
able
)
{
var
result
=
false
_table
.
associations
.
forEach
(
function
(
association
)
{
if
((
association
.
table
.
tableName
==
table
.
tableName
)
&&
(
association
.
type
==
'hasMany'
))
var
myTableName
=
table
.
tableName
associatedTable
.
associations
.
forEach
(
function
(
association
)
{
if
((
association
.
table
.
tableName
==
myTableName
)
&&
(
association
.
type
==
'hasMany'
))
result
=
true
})
return
result
...
...
@@ -35,20 +37,16 @@ SequelizeTable = function(sequelize, tableName, attributes) {
table
.
associations
.
forEach
(
function
(
association
)
{
switch
(
association
.
type
)
{
case
'hasMany'
:
if
(
association
.
table
.
isCrossAssociatedWith
(
association
.
table
))
{
if
(
association
.
table
.
isCrossAssociatedWith
(
table
))
{
// many to many relation
SequelizeHelper
.
log
(
association
)
var
_attributes
=
{}
_attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
_attributes
[
association
.
table
.
identifier
]
=
Sequelize
.
INTEGER
SequelizeHelper
.
log
(
table
.
tableName
+
association
.
table
.
tableName
)
sequelize
.
define
(
table
.
tableName
+
association
.
table
.
tableName
,
_attributes
)
sequelize
.
define
([
table
.
tableName
,
association
.
table
.
tableName
].
sort
().
join
(
""
),
_attributes
)
}
else
{
// one to many relation
association
.
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
}
break
case
'hasOne'
:
// e.g. assocTable.myTableId = Sequelize.INTEGER
...
...
@@ -63,8 +61,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
},
sync
:
function
(
callback
)
{
table
.
prepareAssociations
()
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
SequelizeHelper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
type
,
name
)
{
fields
.
push
(
name
+
" "
+
type
)
...
...
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