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 9ef6a23c
authored
Jan 27, 2012
by
Meg Sharkey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more logging fixes
1 parent
cb7adce6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
0 deletions
lib/associations/has-many-double-linked.js
lib/model-factory.js
lib/query-chainer.js
spec/associations/has-many.spec.js
lib/associations/has-many-double-linked.js
View file @
9ef6a23
...
...
@@ -21,6 +21,7 @@ module.exports = (function() {
self
.
__factory
.
target
.
findAllJoin
(
self
.
__factory
.
connectorModel
.
tableName
,
{
where
:
where
})
.
on
(
'success'
,
function
(
objects
)
{
customEventEmitter
.
emit
(
'success'
,
objects
)
})
.
on
(
'failure'
,
function
(
err
){
customEventEmitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
customEventEmitter
.
emit
(
'sql'
,
sql
)})
})
return
customEventEmitter
.
run
()
...
...
@@ -31,6 +32,7 @@ module.exports = (function() {
destroyObsoleteAssociations
.
call
(
this
,
oldAssociations
,
newAssociations
)
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
.
success
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
,
association
=
self
.
__factory
.
target
.
associations
[
self
.
__factory
.
associationAccessor
]
...
...
@@ -49,6 +51,7 @@ module.exports = (function() {
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
})
}
...
...
@@ -82,6 +85,7 @@ module.exports = (function() {
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
}
})
})
...
...
lib/model-factory.js
View file @
9ef6a23
...
...
@@ -68,6 +68,7 @@ module.exports = (function() {
.
createTable
(
self
.
tableName
,
self
.
attributes
,
options
)
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
self
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
}
if
(
options
.
force
)
...
...
lib/query-chainer.js
View file @
9ef6a23
...
...
@@ -99,6 +99,7 @@ module.exports = (function() {
self
.
fails
.
push
(
err
)
finish
.
call
(
self
)
})
.
on
(
'sql'
,
function
(
sql
){
self
.
eventEmitter
.
emit
(
'sql'
,
sql
)
})
}
var
finish
=
function
()
{
...
...
spec/associations/has-many.spec.js
View file @
9ef6a23
...
...
@@ -240,6 +240,45 @@ describe('HasMany', function() {
})
})
it
(
"allows join table to be specified"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
var
Child
=
sequelize
.
define
(
'Child'
,
{
name
:
Sequelize
.
STRING
},
{
underscore
:
true
,
freezeTableName
:
true
})
var
Parent
=
sequelize
.
define
(
'Parent'
,
{
name
:
Sequelize
.
STRING
},
{
underscore
:
true
,
freezeTableName
:
true
})
var
ParentJoin
=
sequelize
.
define
(
'ParentRelationship'
,
{
parent_id
:
Sequelize
.
INTEGER
,
child_id
:
Sequelize
.
INTEGER
},
{
underscore
:
true
,
freezeTableName
:
true
})
Parent
.
hasMany
(
Child
,
{
as
:
'Children'
,
foreignKey
:
'child_id'
,
joinTableName
:
'ParentRelationship'
})
Child
.
hasMany
(
Parent
,
{
as
:
'Parents'
,
foreignKey
:
'parent_id'
,
joinTableName
:
'ParentRelationship'
})
var
parents
=
[]
ParentJoin
.
sync
({
force
:
true
}).
success
(
function
()
{
Parent
.
sync
({
force
:
true
}).
success
(
function
()
{
Child
.
sync
({
force
:
true
}).
success
(
function
()
{
Parent
.
create
({
name
:
'mom'
}).
success
(
function
(
mom
)
{
parents
.
push
(
mom
)
Parent
.
create
({
name
:
'dad'
}).
success
(
function
(
dad
)
{
parents
.
push
(
dad
)
Child
.
create
({
name
:
'baby'
}).
success
(
function
(
baby
)
{
baby
.
setParents
(
parents
).
success
(
function
(){
parents
[
0
].
getChildren
().
success
(
function
(
children
){
expect
(
children
).
not
.
toBe
(
null
)
expect
(
children
.
length
).
toBeDefined
()
expect
(
children
.
length
).
toEqual
(
1
)
expect
(
children
[
0
]).
toBeDefined
()
expect
(
children
[
0
].
name
).
toEqual
(
'baby'
)
done
()
})
})
})
})
})
})
})
})
})
})
it
(
"gets and sets the connector models"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
var
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
})
...
...
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