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 54e1d51d
authored
Jan 03, 2011
by
Israel De La Hoz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add dinamic timestamp fields names to sequelize tables
1 parent
a4c973f4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
lib/sequelize/Sequelize.js
lib/sequelize/SequelizeTable.js
lib/sequelize/Sequelize.js
View file @
54e1d51
...
@@ -88,6 +88,13 @@ Sequelize.prototype = {
...
@@ -88,6 +88,13 @@ Sequelize.prototype = {
define
:
function
(
name
,
attributes
,
options
)
{
define
:
function
(
name
,
attributes
,
options
)
{
var
SequelizeTable
=
require
(
__dirname
+
"/SequelizeTable"
).
SequelizeTable
var
SequelizeTable
=
require
(
__dirname
+
"/SequelizeTable"
).
SequelizeTable
var
_attributes
=
{}
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
)
{
Sequelize
.
Helper
.
Hash
.
forEach
(
attributes
,
function
(
value
,
key
)
{
if
(
typeof
value
==
'string'
)
if
(
typeof
value
==
'string'
)
...
@@ -98,8 +105,8 @@ Sequelize.prototype = {
...
@@ -98,8 +105,8 @@ Sequelize.prototype = {
throw
new
Error
(
"Please specify a datatype either by using Sequelize.* or pass a hash!"
)
throw
new
Error
(
"Please specify a datatype either by using Sequelize.* or pass a hash!"
)
})
})
_attributes
.
createdAt
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
_attributes
[
createdAt
]
=
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
_attributes
.
updatedAt
=
{
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
)
var
table
=
new
SequelizeTable
(
Sequelize
,
this
,
Sequelize
.
Helper
.
SQL
.
asTableName
(
name
),
_attributes
,
options
)
...
...
lib/sequelize/SequelizeTable.js
View file @
54e1d51
...
@@ -10,6 +10,13 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -10,6 +10,13 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
options
.
classMethods
=
options
.
classMethods
||
{}
options
.
classMethods
=
options
.
classMethods
||
{}
options
.
instanceMethods
=
options
.
instanceMethods
||
{}
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
table
=
function
(
values
)
{
var
self
=
this
,
var
self
=
this
,
defaults
=
{}
defaults
=
{}
...
@@ -292,7 +299,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -292,7 +299,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
self
=
this
self
=
this
Sequelize
.
Helper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
options
,
attribute
)
{
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
allowsNull
=
((
typeof
options
.
allowNull
==
'undefined'
)
||
(
options
.
allowNull
!==
false
))
var
hasDefault
=
(
typeof
options
.
default
!=
'undefined'
)
var
hasDefault
=
(
typeof
options
.
default
!=
'undefined'
)
...
@@ -356,9 +363,9 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -356,9 +363,9 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
throw
new
Error
(
errorText
)
throw
new
Error
(
errorText
)
}
}
this
.
updatedAt
=
new
Date
()
this
[
updatedAt
]
=
new
Date
()
if
(
this
.
isNewRecord
)
{
if
(
this
.
isNewRecord
)
{
this
.
createdAt
=
new
Date
()
this
[
createdAt
]
=
new
Date
()
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
table
.
tableName
,
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