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 8319ed59
authored
Jul 29, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug in associations
1 parent
dca14ce1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
src/SequelizeTable.js
src/SequelizeTable.js
View file @
8319ed5
/*
A.hasOne(B) => B.aId
A.belongsTo(B) => A.bId
A.hasMany(B) => B.aId
A.hasMany(B) + B.hasMany(A) => AB.aId + AB.bId
*/
SequelizeTable
=
function
(
sequelize
,
tableName
,
attributes
)
{
SequelizeTable
=
function
(
sequelize
,
tableName
,
attributes
)
{
var
table
=
function
(
values
)
{
var
table
=
function
(
values
)
{
var
self
=
this
var
self
=
this
...
@@ -24,13 +31,19 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -24,13 +31,19 @@ SequelizeTable = function(sequelize, tableName, attributes) {
return
result
return
result
},
},
sync
:
function
(
callback
)
{
prepareAssociations
:
function
(
)
{
table
.
associations
.
forEach
(
function
(
association
)
{
table
.
associations
.
forEach
(
function
(
association
)
{
switch
(
association
.
type
)
{
switch
(
association
.
type
)
{
case
'hasMany'
:
case
'hasMany'
:
if
(
association
.
table
.
isCrossAssociatedWith
(
association
.
table
))
{
if
(
association
.
table
.
isCrossAssociatedWith
(
association
.
table
))
{
// many to many relation
// 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
)
}
else
{
}
else
{
// one to many relation
// one to many relation
association
.
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
association
.
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
...
@@ -43,10 +56,14 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -43,10 +56,14 @@ SequelizeTable = function(sequelize, tableName, attributes) {
break
break
case
'belongsTo'
:
case
'belongsTo'
:
// e.g. table.dayId = Sequelize.INTEGER
// e.g. table.dayId = Sequelize.INTEGER
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
table
.
attributes
[
association
.
table
.
identifier
]
=
Sequelize
.
INTEGER
break
break
}
}
})
})
},
sync
:
function
(
callback
)
{
table
.
prepareAssociations
()
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
SequelizeHelper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
type
,
name
)
{
SequelizeHelper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
type
,
name
)
{
...
...
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