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 d0f998a0
authored
Apr 28, 2014
by
José Moreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
This is paranoid's fault too
1 parent
a96f6ee1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
25 deletions
test/include/findAndCountAll.test.js
test/include/findAndCountAll.test.js
View file @
d0f998a
...
...
@@ -15,15 +15,15 @@ describe(Support.getTestDialectTeaser("Include"), function () {
it
(
'Try to include a required model. Result rows should match count'
,
function
(
done
)
{
var
DT
=
DataTypes
,
S
=
this
.
sequelize
,
User
=
S
.
define
(
'User'
,
{
name
:
DT
.
STRING
(
40
)
}),
User
=
S
.
define
(
'User'
,
{
name
:
DT
.
STRING
(
40
)
}
,
{
paranoid
:
true
}
),
SomeConnection
=
S
.
define
(
'SomeConnection'
,
{
m
:
DT
.
STRING
(
40
),
fk
:
DT
.
INTEGER
.
UNSIGNED
,
u
:
DT
.
INTEGER
.
UNSIGNED
,
}),
A
=
S
.
define
(
'A'
,
{
name
:
DT
.
STRING
(
40
)
}),
B
=
S
.
define
(
'B'
,
{
name
:
DT
.
STRING
(
40
)
}),
C
=
S
.
define
(
'C'
,
{
name
:
DT
.
STRING
(
40
)
})
}
,
{
paranoid
:
true
}
),
A
=
S
.
define
(
'A'
,
{
name
:
DT
.
STRING
(
40
)
}
,
{
paranoid
:
true
}
),
B
=
S
.
define
(
'B'
,
{
name
:
DT
.
STRING
(
40
)
}
,
{
paranoid
:
true
}
),
C
=
S
.
define
(
'C'
,
{
name
:
DT
.
STRING
(
40
)
}
,
{
paranoid
:
true
}
)
// Associate them
User
.
hasMany
(
SomeConnection
)
...
...
@@ -34,13 +34,13 @@ describe(Support.getTestDialectTeaser("Include"), function () {
.
belongsTo
(
B
,
{
foreignKey
:
'fk'
,
})
.
belongsTo
(
C
,
{
foreignKey
:
'fk'
,
})
A
.
hasMany
(
SomeConnection
)
B
.
hasMany
(
SomeConnection
)
C
.
hasMany
(
SomeConnection
)
A
.
hasMany
(
SomeConnection
,
{
foreignKey
:
'fk'
,
}
)
B
.
hasMany
(
SomeConnection
,
{
foreignKey
:
'fk'
,
}
)
C
.
hasMany
(
SomeConnection
,
{
foreignKey
:
'fk'
,
}
)
// Sync them
S
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
// Create an enviroment
User
.
bulkCreate
([
{
name
:
'Youtube'
},
...
...
@@ -51,12 +51,22 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]).
done
(
function
(
err
,
users
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
users
).
to
.
be
.
length
(
5
)
SomeConnection
.
bulkCreate
([
// Lets count, m: A and u: 1
{
u
:
1
,
m
:
'A'
,
fk
:
1
},
// 1
{
u
:
1
,
m
:
'A'
,
fk
:
1
},
// 1
// Will be deleted
{
u
:
2
,
m
:
'A'
,
fk
:
1
},
{
u
:
3
,
m
:
'A'
,
fk
:
1
},
{
u
:
4
,
m
:
'A'
,
fk
:
1
},
{
u
:
5
,
m
:
'A'
,
fk
:
1
},
{
u
:
1
,
m
:
'B'
,
fk
:
1
},
{
u
:
2
,
m
:
'B'
,
fk
:
1
},
{
u
:
3
,
m
:
'B'
,
fk
:
1
},
{
u
:
4
,
m
:
'B'
,
fk
:
1
},
{
u
:
5
,
m
:
'B'
,
fk
:
1
},
{
u
:
1
,
m
:
'C'
,
fk
:
1
},
{
u
:
1
,
m
:
'A'
,
fk
:
2
},
// 2
{
u
:
2
,
m
:
'C'
,
fk
:
1
},
{
u
:
3
,
m
:
'C'
,
fk
:
1
},
{
u
:
4
,
m
:
'C'
,
fk
:
1
},
{
u
:
5
,
m
:
'C'
,
fk
:
1
},
{
u
:
1
,
m
:
'A'
,
fk
:
2
},
// 2 // Will be deleted
{
u
:
4
,
m
:
'A'
,
fk
:
2
},
{
u
:
2
,
m
:
'A'
,
fk
:
2
},
{
u
:
1
,
m
:
'A'
,
fk
:
3
},
// 3
...
...
@@ -65,7 +75,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{
u
:
2
,
m
:
'B'
,
fk
:
2
},
{
u
:
1
,
m
:
'A'
,
fk
:
4
},
// 4
{
u
:
4
,
m
:
'A'
,
fk
:
2
},
]).
done
(
function
(
err
,
conns
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
conns
).
to
.
be
.
length
(
1
4
)
]).
done
(
function
(
err
,
conns
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
conns
).
to
.
be
.
length
(
2
4
)
A
.
bulkCreate
([
{
name
:
'Just'
},
...
...
@@ -84,15 +94,14 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{
name
:
'because we only want A'
}
]).
done
(
function
(
err
,
cs
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
cs
).
to
.
be
.
length
(
1
)
// Now let's query an initial test
A
.
findAndCountAll
().
done
(
function
(
err
,
result
)
{
// Test variables
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
result
.
count
).
to
.
be
.
equal
(
5
)
expect
(
result
.
rows
.
length
).
to
.
be
.
equal
(
5
)
// Delete some of conns to prove the concept
SomeConnection
.
destroy
({
m
:
'A'
,
u
:
1
,
fk
:
[
1
,
2
],
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
// Last and most important queries
// Last and most important queries
( we connected 4, but deleted 2, witch means we must get 2 only )
A
.
findAndCountAll
({
include
:
[{
...
...
@@ -105,19 +114,20 @@ describe(Support.getTestDialectTeaser("Include"), function () {
limit
:
5
,
}).
done
(
function
(
err
,
result
)
{
})
.
done
(
function
(
err
,
result
)
{
// Test variables
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
result
.
count
).
to
.
be
.
equal
(
4
)
expect
(
result
.
rows
.
length
).
to
.
be
.
equal
(
4
)
expect
(
result
.
count
).
to
.
be
.
equal
(
2
)
expect
(
result
.
rows
.
length
).
to
.
be
.
equal
(
2
)
done
()
// Last and most important queries - END
})
//
Now let's query an initial tes
t - END
//
Delete some of conns to prove the concep
t - END
})
// Create an enviroment - END
...
...
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