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 f7904548
authored
Dec 30, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bulkCreate so it sets the returned autoincremented primary key values on the daos
1 parent
5517acd8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
4 deletions
lib/dao-factory.js
lib/dialects/postgres/query.js
test/dao-factory/create.test.js
test/include.test.js
lib/dao-factory.js
View file @
f790454
...
@@ -786,7 +786,14 @@ module.exports = (function() {
...
@@ -786,7 +786,14 @@ module.exports = (function() {
})
})
.
error
(
function
(
err
)
{
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
emitter
.
emit
(
'error'
,
err
)
}).
success
(
function
()
{
}).
success
(
function
(
rows
)
{
rows
.
forEach
(
function
(
row
,
i
)
{
Object
.
keys
(
daos
[
i
].
__factory
.
primaryKeys
).
concat
(
'id'
).
forEach
(
function
(
primarKey
)
{
if
(
row
.
hasOwnProperty
(
primarKey
))
{
daos
[
i
].
setDataValue
(
primarKey
,
row
[
primarKey
])
}
})
})
done
()
done
()
})
})
}
}
...
...
lib/dialects/postgres/query.js
View file @
f790454
...
@@ -37,6 +37,7 @@ module.exports = (function() {
...
@@ -37,6 +37,7 @@ module.exports = (function() {
query
.
on
(
'error'
,
function
(
err
)
{
query
.
on
(
'error'
,
function
(
err
)
{
receivedError
=
true
receivedError
=
true
err
.
sql
=
sql
err
.
sql
=
sql
self
.
emit
(
'sql'
,
sql
)
self
.
emit
(
'error'
,
err
,
self
.
callee
)
self
.
emit
(
'error'
,
err
,
self
.
callee
)
})
})
...
@@ -125,6 +126,7 @@ module.exports = (function() {
...
@@ -125,6 +126,7 @@ module.exports = (function() {
})
})
})
})
}
}
this
.
emit
(
'success'
,
this
.
send
(
'handleSelectQuery'
,
rows
))
this
.
emit
(
'success'
,
this
.
send
(
'handleSelectQuery'
,
rows
))
}
}
}
else
if
(
this
.
send
(
'isShowOrDescribeQuery'
))
{
}
else
if
(
this
.
send
(
'isShowOrDescribeQuery'
))
{
...
@@ -140,9 +142,10 @@ module.exports = (function() {
...
@@ -140,9 +142,10 @@ module.exports = (function() {
this
.
callee
[
key
]
=
record
this
.
callee
[
key
]
=
record
}
}
}
}
}
this
.
emit
(
'success'
,
this
.
callee
)
}
else
{
this
.
emit
(
'success'
,
this
.
callee
)
this
.
emit
(
'success'
,
rows
)
}
}
else
if
(
this
.
send
(
'isUpdateQuery'
))
{
}
else
if
(
this
.
send
(
'isUpdateQuery'
))
{
if
(
this
.
callee
!==
null
)
{
// may happen for bulk updates
if
(
this
.
callee
!==
null
)
{
// may happen for bulk updates
for
(
var
key
in
rows
[
0
])
{
for
(
var
key
in
rows
[
0
])
{
...
...
test/dao-factory/create.test.js
View file @
f790454
...
@@ -894,6 +894,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -894,6 +894,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'should return instances with primary key values (autoincremented)'
,
function
(
done
)
{
var
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{})
Worker
.
sync
().
done
(
function
(
err
)
{
Worker
.
bulkCreate
([{},
{}]).
done
(
function
(
err
,
workers
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
workers
).
to
.
be
.
ok
workers
.
forEach
(
function
(
worker
)
{
expect
(
worker
.
id
).
to
.
be
.
ok
})
done
()
})
})
})
describe
(
'enums'
,
function
()
{
describe
(
'enums'
,
function
()
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
...
...
test/include.test.js
View file @
f790454
...
@@ -106,4 +106,32 @@ it('should support a simple nested hasOne -> hasOne include', function (done) {
...
@@ -106,4 +106,32 @@ it('should support a simple nested hasOne -> hasOne include', function (done) {
})
})
})
})
})
})
it
(
'should support a simple nested hasMany -> belongsTo include'
,
function
(
done
)
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Project
=
this
.
sequelize
.
define
(
'Project'
,
{})
User
.
hasMany
(
Task
)
Task
.
belongsTo
(
Project
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
async
.
auto
({
user
:
function
(
callback
)
{
User
.
create
().
done
(
callback
)
},
projects
:
function
(
callback
)
{
Project
.
bulkCreate
([{},
{}]).
done
(
callback
)
},
tasks
:
[
'projects'
,
function
(
callback
,
results
)
{
Task
.
bulkCreate
([
{
ProjectId
:
results
.
projects
[
0
].
id
},
{
ProjectId
:
results
.
projects
[
1
].
id
},
{
ProjectId
:
results
.
projects
[
0
].
id
},
{
ProjectId
:
results
.
projects
[
1
].
id
}
]).
done
(
callback
)
}]
},
done
);
});
})
})
})
\ No newline at end of file
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