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 a4288ad7
authored
Apr 07, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default query type to select when callee is set. Closes #3415
1 parent
6ef3ed62
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
6 deletions
lib/instance.js
lib/model.js
lib/query-interface.js
lib/query-types.js
lib/sequelize.js
test/integration/sequelize.test.js
lib/instance.js
View file @
a4288ad
...
...
@@ -8,6 +8,7 @@ var Utils = require('./utils')
,
BelongsToMany
=
require
(
'./associations/belongs-to-many'
)
,
InstanceValidator
=
require
(
'./instance-validator'
)
,
DataTypes
=
require
(
'./data-types'
)
,
QueryTypes
=
require
(
'./query-types'
)
,
Promise
=
require
(
"./promise"
)
,
_
=
require
(
'lodash'
)
,
defaultsOptions
=
{
raw
:
true
}
...
...
@@ -589,7 +590,7 @@ module.exports = (function() {
// Nested creation for BelongsTo relations
return
Promise
.
map
(
this
.
options
.
include
.
filter
(
function
(
include
)
{
return
include
.
association
instanceof
BelongsTo
;
return
include
.
association
instanceof
BelongsTo
;
}),
function
(
include
)
{
var
instance
=
self
.
get
(
include
.
as
);
if
(
!
instance
)
return
Promise
.
resolve
();
...
...
@@ -808,7 +809,7 @@ module.exports = (function() {
}
else
{
where
=
{};
where
[
self
.
Model
.
rawAttributes
[
self
.
Model
.
primaryKeyAttribute
].
field
]
=
self
.
get
(
self
.
Model
.
primaryKeyAttribute
,
{
raw
:
true
});
return
self
.
QueryInterface
.
delete
(
self
,
self
.
Model
.
getTableName
(
options
),
where
,
_
.
defaults
(
options
,
{
limit
:
null
}));
return
self
.
QueryInterface
.
delete
(
self
,
self
.
Model
.
getTableName
(
options
),
where
,
_
.
defaults
(
options
,
{
type
:
QueryTypes
.
DELETE
,
limit
:
null
}));
}
}).
tap
(
function
(
result
)
{
// Run after hook
...
...
lib/model.js
View file @
a4288ad
...
...
@@ -1533,7 +1533,7 @@ module.exports = (function() {
individualHooks
:
false
},
options
||
{});
options
.
type
=
QueryTypes
.
BULKUNDELETE
;
options
.
type
=
QueryTypes
.
RAW
;
var
self
=
this
,
instances
;
...
...
lib/query-interface.js
View file @
a4288ad
...
...
@@ -686,6 +686,8 @@ module.exports = (function() {
QueryInterface
.
prototype
.
increment
=
function
(
dao
,
tableName
,
values
,
identifier
,
options
)
{
var
sql
=
this
.
QueryGenerator
.
incrementQuery
(
tableName
,
values
,
identifier
,
options
.
attributes
);
options
.
type
=
QueryTypes
.
RAW
;
return
this
.
sequelize
.
query
(
sql
,
dao
,
options
);
};
...
...
lib/query-types.js
View file @
a4288ad
...
...
@@ -6,6 +6,7 @@ module.exports = {
UPDATE
:
'UPDATE'
,
BULKUPDATE
:
'BULKUPDATE'
,
BULKDELETE
:
'BULKDELETE'
,
DELETE
:
'DELETE'
,
UPSERT
:
'UPSERT'
,
VERSION
:
'VERSION'
,
SHOWTABLES
:
'SHOWTABLES'
,
...
...
lib/sequelize.js
View file @
a4288ad
...
...
@@ -653,7 +653,7 @@ module.exports = (function() {
*
* @method query
* @param {String} sql
* @param {Instance|Model} [callee] If callee is provided, the returned data will be put into the callee
* @param {Instance|Model} [callee] If callee is provided, the returned data will be put into the callee
, and `type` will default to SELECT
* @param {Object} [options={}] Query options.
* @param {Boolean} [options.raw] If true, sequelize will not try to format the results of the query, or build an instance of a model from the result
* @param {Transaction} [options.transaction=null] The transaction that the query should be executed under
...
...
@@ -725,7 +725,7 @@ module.exports = (function() {
}
if
(
!
options
.
type
)
{
if
(
options
.
nest
||
options
.
plain
)
{
if
(
callee
||
options
.
nest
||
options
.
plain
)
{
options
.
type
=
QueryTypes
.
SELECT
;
}
else
{
options
.
type
=
QueryTypes
.
RAW
;
...
...
test/integration/sequelize.test.js
View file @
a4288ad
...
...
@@ -284,7 +284,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
it
(
'uses the passed model'
,
function
()
{
return
this
.
sequelize
.
query
(
this
.
insertQuery
).
bind
(
this
).
then
(
function
()
{
return
this
.
sequelize
.
query
(
'SELECT * FROM '
+
qq
(
this
.
User
.
tableName
)
+
';'
,
this
.
User
,
{
type
:
this
.
sequelize
.
QueryTypes
.
SELECT
}
);
return
this
.
sequelize
.
query
(
'SELECT * FROM '
+
qq
(
this
.
User
.
tableName
)
+
';'
,
this
.
User
);
}).
then
(
function
(
users
)
{
expect
(
users
[
0
].
Model
).
to
.
equal
(
this
.
User
);
});
...
...
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