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 053145cd
authored
Oct 02, 2018
by
frlinw
Committed by
Sushant
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(model): remove .all alias (#9975)
1 parent
f7585ac0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
18 additions
and
27 deletions
docs/models-usage.md
lib/model.js
test/integration/associations/belongs-to-many.test.js
test/integration/associations/belongs-to.test.js
test/integration/associations/has-many.test.js
test/integration/associations/has-one.test.js
test/integration/model/scope/find.test.js
test/integration/sequelize.transaction.test.js
test/unit/model/validation.test.js
docs/models-usage.md
View file @
053145c
...
@@ -150,11 +150,6 @@ Project.findAll().then(projects => {
...
@@ -150,11 +150,6 @@ Project.findAll().then(projects => {
// projects will be an array of all Project instances
// projects will be an array of all Project instances
})
})
// also possible:
Project
.
all
().
then
(
projects
=>
{
// projects will be an array of all Project instances
})
// search for specific attributes - hash usage
// search for specific attributes - hash usage
Project
.
findAll
({
where
:
{
name
:
'A Project'
}
}).
then
(
projects
=>
{
Project
.
findAll
({
where
:
{
name
:
'A Project'
}
}).
then
(
projects
=>
{
// projects will be an array of Project instances with the specified name
// projects will be an array of Project instances with the specified name
...
...
lib/model.js
View file @
053145c
...
@@ -1556,10 +1556,6 @@ class Model {
...
@@ -1556,10 +1556,6 @@ class Model {
return
self
;
return
self
;
}
}
static
all
(
options
)
{
return
this
.
findAll
(
options
);
}
/**
/**
* Search for multiple instances.
* Search for multiple instances.
*
*
...
...
test/integration/associations/belongs-to-many.test.js
View file @
053145c
...
@@ -55,12 +55,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -55,12 +55,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this
.
t
=
t
;
this
.
t
=
t
;
return
article
.
setLabels
([
label
],
{
transaction
:
t
});
return
article
.
setLabels
([
label
],
{
transaction
:
t
});
}).
then
(
function
()
{
}).
then
(
function
()
{
return
this
.
Article
.
a
ll
({
transaction
:
this
.
t
});
return
this
.
Article
.
findA
ll
({
transaction
:
this
.
t
});
}).
then
(
articles
=>
{
}).
then
(
articles
=>
{
return
articles
[
0
].
getLabels
();
return
articles
[
0
].
getLabels
();
}).
then
(
function
(
labels
)
{
}).
then
(
function
(
labels
)
{
expect
(
labels
).
to
.
have
.
length
(
0
);
expect
(
labels
).
to
.
have
.
length
(
0
);
return
this
.
Article
.
a
ll
({
transaction
:
this
.
t
});
return
this
.
Article
.
findA
ll
({
transaction
:
this
.
t
});
}).
then
(
function
(
articles
)
{
}).
then
(
function
(
articles
)
{
return
articles
[
0
].
getLabels
({
transaction
:
this
.
t
});
return
articles
[
0
].
getLabels
({
transaction
:
this
.
t
});
}).
then
(
function
(
labels
)
{
}).
then
(
function
(
labels
)
{
...
...
test/integration/associations/belongs-to.test.js
View file @
053145c
...
@@ -77,10 +77,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
...
@@ -77,10 +77,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
Group
.
a
ll
().
then
(
groups
=>
{
return
Group
.
findA
ll
().
then
(
groups
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
expect
(
associatedUser
).
to
.
be
.
null
;
expect
(
associatedUser
).
to
.
be
.
null
;
return
Group
.
a
ll
({
transaction
:
t
}).
then
(
groups
=>
{
return
Group
.
findA
ll
({
transaction
:
t
}).
then
(
groups
=>
{
return
groups
[
0
].
getUser
({
transaction
:
t
}).
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
({
transaction
:
t
}).
then
(
associatedUser
=>
{
expect
(
associatedUser
).
to
.
be
.
not
.
null
;
expect
(
associatedUser
).
to
.
be
.
not
.
null
;
return
t
.
rollback
();
return
t
.
rollback
();
...
@@ -207,7 +207,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
...
@@ -207,7 +207,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
Group
.
a
ll
().
then
(
groups
=>
{
return
Group
.
findA
ll
().
then
(
groups
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
expect
(
associatedUser
).
to
.
be
.
null
;
expect
(
associatedUser
).
to
.
be
.
null
;
return
t
.
rollback
();
return
t
.
rollback
();
...
...
test/integration/associations/has-many.test.js
View file @
053145c
...
@@ -488,13 +488,13 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
...
@@ -488,13 +488,13 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
t
=
_t
;
t
=
_t
;
return
article
.
setLabels
([
label
],
{
transaction
:
t
});
return
article
.
setLabels
([
label
],
{
transaction
:
t
});
}).
then
(()
=>
{
}).
then
(()
=>
{
return
Article
.
a
ll
({
transaction
:
t
});
return
Article
.
findA
ll
({
transaction
:
t
});
}).
then
(
articles
=>
{
}).
then
(
articles
=>
{
return
articles
[
0
].
hasLabel
(
label
).
then
(
hasLabel
=>
{
return
articles
[
0
].
hasLabel
(
label
).
then
(
hasLabel
=>
{
expect
(
hasLabel
).
to
.
be
.
false
;
expect
(
hasLabel
).
to
.
be
.
false
;
});
});
}).
then
(()
=>
{
}).
then
(()
=>
{
return
Article
.
a
ll
({
transaction
:
t
});
return
Article
.
findA
ll
({
transaction
:
t
});
}).
then
(
articles
=>
{
}).
then
(
articles
=>
{
return
articles
[
0
].
hasLabel
(
label
,
{
transaction
:
t
}).
then
(
hasLabel
=>
{
return
articles
[
0
].
hasLabel
(
label
,
{
transaction
:
t
}).
then
(
hasLabel
=>
{
expect
(
hasLabel
).
to
.
be
.
true
;
expect
(
hasLabel
).
to
.
be
.
true
;
...
@@ -594,7 +594,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
...
@@ -594,7 +594,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
this
.
t
=
t
;
this
.
t
=
t
;
return
this
.
article
.
setLabels
([
this
.
label
],
{
transaction
:
t
});
return
this
.
article
.
setLabels
([
this
.
label
],
{
transaction
:
t
});
}).
then
(
function
()
{
}).
then
(
function
()
{
return
this
.
Article
.
a
ll
({
transaction
:
this
.
t
});
return
this
.
Article
.
findA
ll
({
transaction
:
this
.
t
});
}).
then
(
function
(
articles
)
{
}).
then
(
function
(
articles
)
{
return
Promise
.
all
([
return
Promise
.
all
([
articles
[
0
].
hasLabels
([
this
.
label
]),
articles
[
0
].
hasLabels
([
this
.
label
]),
...
...
test/integration/associations/has-one.test.js
View file @
053145c
...
@@ -76,10 +76,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
...
@@ -76,10 +76,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
Group
.
a
ll
().
then
(
groups
=>
{
return
Group
.
findA
ll
().
then
(
groups
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
expect
(
associatedUser
).
to
.
be
.
null
;
expect
(
associatedUser
).
to
.
be
.
null
;
return
Group
.
a
ll
({
transaction
:
t
}).
then
(
groups
=>
{
return
Group
.
findA
ll
({
transaction
:
t
}).
then
(
groups
=>
{
return
groups
[
0
].
getUser
({
transaction
:
t
}).
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
({
transaction
:
t
}).
then
(
associatedUser
=>
{
expect
(
associatedUser
).
not
.
to
.
be
.
null
;
expect
(
associatedUser
).
not
.
to
.
be
.
null
;
expect
(
associatedUser
.
id
).
to
.
equal
(
user
.
id
);
expect
(
associatedUser
.
id
).
to
.
equal
(
user
.
id
);
...
@@ -140,7 +140,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
...
@@ -140,7 +140,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
]);
]);
}).
spread
((
fakeUser
,
user
,
group
)
=>
{
}).
spread
((
fakeUser
,
user
,
group
)
=>
{
return
group
.
setUser
(
user
).
then
(()
=>
{
return
group
.
setUser
(
user
).
then
(()
=>
{
return
Group
.
a
ll
().
then
(
groups
=>
{
return
Group
.
findA
ll
().
then
(
groups
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
expect
(
associatedUser
).
not
.
to
.
be
.
null
;
expect
(
associatedUser
).
not
.
to
.
be
.
null
;
expect
(
associatedUser
.
id
).
to
.
equal
(
user
.
id
);
expect
(
associatedUser
.
id
).
to
.
equal
(
user
.
id
);
...
@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
...
@@ -174,7 +174,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
Group
.
create
({
name
:
'bar'
}).
then
(
group
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
group
.
setUser
(
user
,
{
transaction
:
t
}).
then
(()
=>
{
return
Group
.
a
ll
().
then
(
groups
=>
{
return
Group
.
findA
ll
().
then
(
groups
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
return
groups
[
0
].
getUser
().
then
(
associatedUser
=>
{
expect
(
associatedUser
).
to
.
be
.
null
;
expect
(
associatedUser
).
to
.
be
.
null
;
return
t
.
rollback
();
return
t
.
rollback
();
...
@@ -365,10 +365,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
...
@@ -365,10 +365,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
return
User
.
create
({
username
:
'bob'
}).
then
(
user
=>
{
return
User
.
create
({
username
:
'bob'
}).
then
(
user
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
sequelize
.
transaction
().
then
(
t
=>
{
return
user
.
createGroup
({
name
:
'testgroup'
},
{
transaction
:
t
}).
then
(()
=>
{
return
user
.
createGroup
({
name
:
'testgroup'
},
{
transaction
:
t
}).
then
(()
=>
{
return
User
.
a
ll
().
then
(
users
=>
{
return
User
.
findA
ll
().
then
(
users
=>
{
return
users
[
0
].
getGroup
().
then
(
group
=>
{
return
users
[
0
].
getGroup
().
then
(
group
=>
{
expect
(
group
).
to
.
be
.
null
;
expect
(
group
).
to
.
be
.
null
;
return
User
.
a
ll
({
transaction
:
t
}).
then
(
users
=>
{
return
User
.
findA
ll
({
transaction
:
t
}).
then
(
users
=>
{
return
users
[
0
].
getGroup
({
transaction
:
t
}).
then
(
group
=>
{
return
users
[
0
].
getGroup
({
transaction
:
t
}).
then
(
group
=>
{
expect
(
group
).
to
.
be
.
not
.
null
;
expect
(
group
).
to
.
be
.
not
.
null
;
return
t
.
rollback
();
return
t
.
rollback
();
...
...
test/integration/model/scope/find.test.js
View file @
053145c
...
@@ -73,7 +73,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -73,7 +73,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it
(
'should be able to use a defaultScope if declared'
,
function
()
{
it
(
'should be able to use a defaultScope if declared'
,
function
()
{
return
this
.
ScopeMe
.
a
ll
().
then
(
users
=>
{
return
this
.
ScopeMe
.
findA
ll
().
then
(
users
=>
{
expect
(
users
).
to
.
have
.
length
(
2
);
expect
(
users
).
to
.
have
.
length
(
2
);
expect
([
10
,
5
].
indexOf
(
users
[
0
].
access_level
)
!==
-
1
).
to
.
be
.
true
;
expect
([
10
,
5
].
indexOf
(
users
[
0
].
access_level
)
!==
-
1
).
to
.
be
.
true
;
expect
([
10
,
5
].
indexOf
(
users
[
1
].
access_level
)
!==
-
1
).
to
.
be
.
true
;
expect
([
10
,
5
].
indexOf
(
users
[
1
].
access_level
)
!==
-
1
).
to
.
be
.
true
;
...
...
test/integration/sequelize.transaction.test.js
View file @
053145c
...
@@ -85,7 +85,7 @@ if (current.dialect.supports.transactions) {
...
@@ -85,7 +85,7 @@ if (current.dialect.supports.transactions) {
return
t
.
commit
();
return
t
.
commit
();
});
});
}).
then
(
function
()
{
}).
then
(
function
()
{
return
this
.
User
.
a
ll
();
return
this
.
User
.
findA
ll
();
}).
then
(
users
=>
{
}).
then
(
users
=>
{
expect
(
users
.
length
).
to
.
equal
(
1
);
expect
(
users
.
length
).
to
.
equal
(
1
);
expect
(
users
[
0
].
name
).
to
.
equal
(
'foo'
);
expect
(
users
[
0
].
name
).
to
.
equal
(
'foo'
);
...
...
test/unit/model/validation.test.js
View file @
053145c
...
@@ -353,7 +353,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -353,7 +353,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
describe
(
'findAll'
,
()
=>
{
describe
(
'findAll'
,
()
=>
{
it
(
'should allow $in'
,
()
=>
{
it
(
'should allow $in'
,
()
=>
{
return
expect
(
User
.
a
ll
({
return
expect
(
User
.
findA
ll
({
where
:
{
where
:
{
name
:
{
name
:
{
[
Op
.
like
]:
{
[
Op
.
like
]:
{
...
@@ -365,7 +365,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -365,7 +365,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
it
(
'should allow $like for uuid'
,
()
=>
{
it
(
'should allow $like for uuid'
,
()
=>
{
return
expect
(
User
.
a
ll
({
return
expect
(
User
.
findA
ll
({
where
:
{
where
:
{
uid
:
{
uid
:
{
[
Op
.
like
]:
'12345678%'
[
Op
.
like
]:
'12345678%'
...
...
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