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 b9c7923e
authored
Jul 26, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added preparation for associations
1 parent
ea83ad35
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletions
src/SequelizeTable.js
src/SequelizeTable.js
View file @
b9c7923
...
@@ -8,10 +8,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -8,10 +8,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
this
.
id
=
null
// specify id as null to declare this object as unsaved and as not present in the database
this
.
id
=
null
// specify id as null to declare this object as unsaved and as not present in the database
this
.
tableName
=
tableName
this
.
tableName
=
tableName
this
.
attributes
=
attributes
this
.
attributes
=
attributes
table
.
associations
.
forEach
(
function
(
association
)
{
self
[
association
.
name
]
=
function
(
callback
)
{
var
myTableName
=
tableName
.
toLowerCase
().
replace
(
/s$/
,
""
)
if
(
association
.
type
=
'hasMany'
)
{
var
whereConditions
=
[
myTableName
+
"Id"
,
self
.
id
].
join
(
"="
)
return
association
.
table
.
findAll
({
where
:
whereConditions
})
}
}
})
}
}
// class methods
// class methods
var
classMethods
=
{
var
classMethods
=
{
associations
:
[],
sync
:
function
(
callback
)
{
sync
:
function
(
callback
)
{
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
SequelizeHelper
.
Hash
.
keys
(
attributes
).
forEach
(
function
(
name
)
{
fields
.
push
(
name
+
" "
+
attributes
[
name
])
})
SequelizeHelper
.
Hash
.
keys
(
attributes
).
forEach
(
function
(
name
)
{
fields
.
push
(
name
+
" "
+
attributes
[
name
])
})
...
@@ -66,6 +78,33 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -66,6 +78,33 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var
object
=
new
table
(
SequelizeHelper
.
Hash
.
merge
({
createdAt
:
new
Date
(),
updatedAt
:
new
Date
()},
result
,
true
))
var
object
=
new
table
(
SequelizeHelper
.
Hash
.
merge
({
createdAt
:
new
Date
(),
updatedAt
:
new
Date
()},
result
,
true
))
object
.
id
=
result
.
id
object
.
id
=
result
.
id
return
object
return
object
},
hasMany
:
function
(
assocName
,
table
)
{
this
.
associations
.
push
({
name
:
assocName
,
table
:
table
,
type
:
'hasMany'
})
return
table
},
hasOne
:
function
(
assocName
,
table
)
{
this
.
associations
.
push
({
name
:
assocName
,
table
:
table
,
type
:
'hasOne'
})
return
table
},
belongsTo
:
function
(
assocName
,
table
)
{
this
.
associations
.
push
({
name
:
assocName
,
table
:
table
,
type
:
'belongsTo'
})
return
table
}
}
}
}
...
@@ -86,7 +125,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -86,7 +125,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var
query
=
null
var
query
=
null
var
self
=
this
var
self
=
this
this
.
updateAt
=
new
Date
()
this
.
update
d
At
=
new
Date
()
if
(
this
.
id
==
null
)
{
if
(
this
.
id
==
null
)
{
this
.
createdAt
=
new
Date
()
this
.
createdAt
=
new
Date
()
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
...
...
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