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 f651fee0
authored
Dec 08, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed update destroy and save query
1 parent
434b85a1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
25 deletions
lib/model.js
lib/query-interface.js
test/Model/destroy.js
lib/model.js
View file @
f651fee
...
@@ -32,16 +32,18 @@ module.exports = (function() {
...
@@ -32,16 +32,18 @@ module.exports = (function() {
})
})
Model
.
prototype
.
save
=
function
()
{
Model
.
prototype
.
save
=
function
()
{
var
a
ttr
=
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
var
updatedAtA
ttr
=
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
if
(
this
.
hasOwnProperty
(
a
ttr
))
if
(
this
.
hasOwnProperty
(
updatedAtA
ttr
))
this
[
a
ttr
]
=
new
Date
()
this
[
updatedAtA
ttr
]
=
new
Date
()
if
(
this
.
isNewRecord
)
{
if
(
this
.
isNewRecord
)
{
return
this
.
QueryInterface
.
insert
(
this
,
this
.
__definition
.
tableName
,
this
.
values
)
return
this
.
QueryInterface
.
insert
(
this
,
this
.
__definition
.
tableName
,
this
.
values
)
}
else
{
}
else
{
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
return
this
.
QueryInterface
.
update
(
this
,
this
.
__definition
.
tableName
,
this
.
values
,
identifier
)
,
query
=
this
.
QueryInterface
.
update
(
this
,
this
.
__definition
.
tableName
,
this
.
values
,
identifier
)
return
query
}
}
}
}
...
@@ -133,7 +135,8 @@ module.exports = (function() {
...
@@ -133,7 +135,8 @@ module.exports = (function() {
Model
.
prototype
.
destroy
=
function
()
{
Model
.
prototype
.
destroy
=
function
()
{
if
(
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
)
{
if
(
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
)
{
this
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
=
new
Date
()
var
attr
=
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
this
[
attr
]
=
new
Date
()
return
this
.
save
()
return
this
.
save
()
}
else
{
}
else
{
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
...
...
lib/query-interface.js
View file @
f651fee
...
@@ -167,35 +167,25 @@ module.exports = (function() {
...
@@ -167,35 +167,25 @@ module.exports = (function() {
QueryInterface
.
prototype
.
insert
=
function
(
model
,
tableName
,
values
)
{
QueryInterface
.
prototype
.
insert
=
function
(
model
,
tableName
,
values
)
{
var
self
=
this
var
self
=
this
,
sql
=
self
.
QueryGenerator
.
insertQuery
(
tableName
,
values
)
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
queryAndEmit
.
call
(
this
,
[
sql
,
model
],
'insert'
,
{
query
success
:
function
(
obj
)
{
obj
.
isNewRecord
=
false
}
.
call
(
self
,
self
.
QueryGenerator
.
insertQuery
(
tableName
,
values
),
model
)
.
success
(
function
(
obj
)
{
self
.
emit
(
'insert'
,
null
)
obj
.
isNewRecord
=
false
emitter
.
emit
(
'success'
,
obj
)
})
})
.
error
(
function
(
err
)
{
self
.
emit
(
'insert'
,
err
)
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
}
QueryInterface
.
prototype
.
update
=
function
(
model
,
tableName
,
values
,
identifier
)
{
QueryInterface
.
prototype
.
update
=
function
(
model
,
tableName
,
values
,
identifier
)
{
var
sql
=
this
.
QueryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
)
var
sql
=
this
.
QueryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
)
,
self
=
this
,
self
=
this
return
queryAndEmit
.
call
(
this
,
sql
,
'update'
)
return
queryAndEmit
.
call
(
this
,
[
sql
,
model
]
,
'update'
)
}
}
QueryInterface
.
prototype
.
delete
=
function
(
model
,
tableName
,
identifier
)
{
QueryInterface
.
prototype
.
delete
=
function
(
model
,
tableName
,
identifier
)
{
var
sql
=
this
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
)
var
sql
=
this
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
)
,
self
=
this
,
self
=
this
return
queryAndEmit
.
call
(
this
,
sql
,
'delete'
)
return
queryAndEmit
.
call
(
this
,
[
sql
,
model
]
,
'delete'
)
}
}
QueryInterface
.
prototype
.
select
=
function
(
factory
,
tableName
,
options
,
queryOptions
)
{
QueryInterface
.
prototype
.
select
=
function
(
factory
,
tableName
,
options
,
queryOptions
)
{
...
@@ -232,14 +222,28 @@ module.exports = (function() {
...
@@ -232,14 +222,28 @@ module.exports = (function() {
// private
// private
var
queryAndEmit
=
function
(
sql
,
methodName
)
{
var
queryAndEmit
=
function
(
sql
OrQueryParams
,
methodName
,
options
)
{
var
self
=
this
var
self
=
this
options
=
Utils
.
_
.
extend
({
success
:
function
(
obj
){},
error
:
function
(
err
){}
},
options
||
{})
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
sequelize
.
query
(
sql
).
success
(
function
()
{
var
query
=
null
if
(
Array
.
isArray
(
sqlOrQueryParams
))
query
=
self
.
sequelize
.
query
.
apply
(
self
.
sequelize
,
sqlOrQueryParams
)
else
query
=
self
.
sequelize
.
query
(
sqlOrQueryParams
)
query
.
success
(
function
(
obj
)
{
options
.
success
&&
options
.
success
(
obj
)
self
.
emit
(
methodName
,
null
)
self
.
emit
(
methodName
,
null
)
emitter
.
emit
(
'success'
,
null
)
emitter
.
emit
(
'success'
,
obj
)
}).
error
(
function
(
err
)
{
}).
error
(
function
(
err
)
{
options
.
error
&&
options
.
error
(
err
)
self
.
emit
(
methodName
,
err
)
self
.
emit
(
methodName
,
err
)
emitter
.
emit
(
'failure'
,
err
)
emitter
.
emit
(
'failure'
,
err
)
})
})
...
...
test/Model/destroy.js
View file @
f651fee
...
@@ -23,9 +23,9 @@ module.exports = {
...
@@ -23,9 +23,9 @@ module.exports = {
'destroy should mark the record as deleted if paranoid is activated'
:
function
(
exit
)
{
'destroy should mark the record as deleted if paranoid is activated'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
},
{
paranoid
:
true
})
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
},
{
paranoid
:
true
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'asd'
,
bio
:
'asd'
}).
on
(
'success'
,
function
(
u
)
{
User
.
create
({
name
:
'asd'
,
bio
:
'asd'
}).
success
(
function
(
u
)
{
assert
.
isNull
(
u
.
deletedAt
)
assert
.
isNull
(
u
.
deletedAt
)
u
.
destroy
().
on
(
'success'
,
function
(
u
)
{
u
.
destroy
().
success
(
function
(
u
)
{
assert
.
isNotNull
(
u
.
deletedAt
)
assert
.
isNotNull
(
u
.
deletedAt
)
exit
(
function
(){})
exit
(
function
(){})
})
})
...
...
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