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 0e26a8da
authored
Mar 29, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
if an insert query was finished add the inserted id to the model
1 parent
7fc980f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
5 deletions
lib/sequelize/model-definition.js
lib/sequelize/model.js
lib/sequelize/query.js
lib/sequelize/model-definition.js
View file @
0e26a8d
...
...
@@ -34,7 +34,7 @@ ModelDefinition.prototype.sync = function(options) {
}
ModelDefinition
.
prototype
.
__defineGetter__
(
'drop'
,
function
()
{
var
query
=
QueryGenerator
.
dropTableQuery
(
this
.
tableName
)
var
query
=
QueryGenerator
.
dropTableQuery
(
this
.
tableName
,
this
.
id
)
return
this
.
modelManager
.
sequelize
.
query
(
query
,
this
)
})
...
...
lib/sequelize/model.js
View file @
0e26a8d
...
...
@@ -31,13 +31,13 @@ Model.prototype.__defineGetter__('save', function() {
var
query
=
QueryGenerator
.
insertQuery
(
this
.
definition
.
tableName
,
this
.
values
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
,
this
)
}
else
{
var
query
=
QueryGenerat
e
.
updateQuery
(
this
.
definition
.
tableName
,
this
.
values
,
this
.
id
)
var
query
=
QueryGenerat
or
.
updateQuery
(
this
.
definition
.
tableName
,
this
.
values
,
this
.
id
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
,
this
)
}
})
Model
.
prototype
.
__defineGetter__
(
'destroy'
,
function
()
{
var
query
=
QueryGenerat
e
.
deleteQuery
(
this
.
definition
.
tableName
,
this
.
id
)
var
query
=
QueryGenerat
or
.
deleteQuery
(
this
.
definition
.
tableName
,
this
.
id
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
,
this
)
})
...
...
lib/sequelize/query.js
View file @
0e26a8d
...
...
@@ -18,8 +18,15 @@ Query.prototype.run = function(query) {
console
.
log
(
'Executing: '
+
query
)
client
.
connect
()
client
.
query
(
query
,
function
()
{
self
.
emit
(
'success'
,
self
.
callee
)
})
client
.
on
(
"error"
,
function
(
err
)
{
self
.
emit
(
'failure'
,
err
,
self
.
callee
)
})
client
.
query
(
query
,
function
(
err
,
info
)
{
if
(
err
)
{
self
.
emit
(
'failure'
,
err
,
self
.
callee
)
}
else
{
if
(
self
.
callee
&&
(
query
.
indexOf
(
'INSERT INTO'
)
==
0
)
&&
(
info
.
hasOwnProperty
(
'insertId'
)))
self
.
callee
.
id
=
info
.
insertId
self
.
emit
(
'success'
,
self
.
callee
)
}
})
client
.
end
()
return
this
...
...
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