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 c83451bc
authored
Feb 27, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'israeldelahoz-master'
2 parents
30eb3bf4
54e1d51d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
lib/sequelize/Sequelize.js
lib/sequelize/SequelizeTable.js
lib/sequelize/Sequelize.js
View file @
c83451b
...
...
@@ -88,7 +88,14 @@ Sequelize.prototype = {
define
:
function
(
name
,
attributes
,
options
)
{
var
SequelizeTable
=
require
(
__dirname
+
"/SequelizeTable"
).
SequelizeTable
var
_attributes
=
{}
var
createdAt
=
"createdAt"
;
var
updatedAt
=
"updatedAt"
;
if
(
options
){
if
(
options
.
createdAt
)
createdAt
=
options
.
createdAt
;
if
(
options
.
updatedAt
)
updatedAt
=
options
.
updatedAt
;
}
Sequelize
.
Helper
.
Hash
.
forEach
(
attributes
,
function
(
value
,
key
)
{
if
(
typeof
value
==
'string'
)
_attributes
[
key
]
=
{
type
:
value
}
...
...
@@ -97,9 +104,9 @@ Sequelize.prototype = {
else
throw
new
Error
(
"Please specify a datatype either by using Sequelize.* or pass a hash!"
)
})
_attributes
.
createdAt
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
_attributes
.
updatedAt
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
_attributes
[
createdAt
]
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
_attributes
[
updatedAt
]
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
var
table
=
new
SequelizeTable
(
Sequelize
,
this
,
Sequelize
.
Helper
.
SQL
.
asTableName
(
name
),
_attributes
,
options
)
...
...
lib/sequelize/SequelizeTable.js
View file @
c83451b
...
...
@@ -10,6 +10,13 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
options
.
classMethods
=
options
.
classMethods
||
{}
options
.
instanceMethods
=
options
.
instanceMethods
||
{}
//for dinamic timestamp field names
var
createdAt
=
"createdAt"
;
var
updatedAt
=
"updatedAt"
;
if
(
options
.
createdAt
)
createdAt
=
options
.
createdAt
;
if
(
options
.
updatedAt
)
updatedAt
=
options
.
updatedAt
;
var
table
=
function
(
values
)
{
var
self
=
this
,
defaults
=
{}
...
...
@@ -292,7 +299,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
self
=
this
Sequelize
.
Helper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
options
,
attribute
)
{
if
([
'createdAt'
,
'updatedAt'
].
indexOf
(
attribute
)
>
-
1
)
return
if
([
createdAt
,
updatedAt
].
indexOf
(
attribute
)
>
-
1
)
return
var
allowsNull
=
((
typeof
options
.
allowNull
==
'undefined'
)
||
(
options
.
allowNull
!==
false
))
var
hasDefault
=
(
typeof
options
.
default
!=
'undefined'
)
...
...
@@ -356,9 +363,9 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
throw
new
Error
(
errorText
)
}
this
.
updatedAt
=
new
Date
()
this
[
updatedAt
]
=
new
Date
()
if
(
this
.
isNewRecord
)
{
this
.
createdAt
=
new
Date
()
this
[
createdAt
]
=
new
Date
()
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
table
.
tableName
,
...
...
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