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 0f1b00df
authored
Jan 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix fix fix
1 parent
e10114fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
22 deletions
lib/dao-factory.js
lib/dao.js
test/mysql/query-generator.test.js
lib/dao-factory.js
View file @
0f1b00d
...
@@ -147,10 +147,7 @@ module.exports = (function() {
...
@@ -147,10 +147,7 @@ module.exports = (function() {
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
})
})
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
timestamps
)
{
this
.
DAO
.
prototype
.
_timestampAttributes
=
{
this
.
DAO
.
prototype
.
_timestampAttributes
=
{
createdAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
),
createdAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
),
updatedAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
),
updatedAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
),
...
...
lib/dao.js
View file @
0f1b00d
...
@@ -112,7 +112,7 @@ module.exports = (function() {
...
@@ -112,7 +112,7 @@ module.exports = (function() {
}
}
// If raw, and we're not dealing with includes, just set it straight on the dataValues object
// If raw, and we're not dealing with includes, just set it straight on the dataValues object
if
(
options
.
raw
&&
!
(
this
.
options
&&
this
.
options
.
include
))
{
if
(
options
.
raw
&&
!
(
this
.
options
&&
this
.
options
.
include
)
&&
!
this
.
_hasBooleanAttributes
&&
!
this
.
_hasReadOnlyAttributes
)
{
if
(
Object
.
keys
(
this
.
dataValues
).
length
)
{
if
(
Object
.
keys
(
this
.
dataValues
).
length
)
{
this
.
dataValues
=
_
.
extend
(
this
.
dataValues
,
values
)
this
.
dataValues
=
_
.
extend
(
this
.
dataValues
,
values
)
}
else
{
}
else
{
...
@@ -144,7 +144,7 @@ module.exports = (function() {
...
@@ -144,7 +144,7 @@ module.exports = (function() {
}
}
// If attempting to set read only attributes, return
// If attempting to set read only attributes, return
if
(
this
.
_hasReadOnlyAttributes
&&
this
.
_isReadOnlyAttribute
(
key
))
{
if
(
!
options
.
raw
&&
this
.
_hasReadOnlyAttributes
&&
this
.
_isReadOnlyAttribute
(
key
))
{
return
return
}
}
...
@@ -632,7 +632,6 @@ module.exports = (function() {
...
@@ -632,7 +632,6 @@ module.exports = (function() {
key
;
key
;
values
=
values
&&
_
.
clone
(
values
)
||
{}
values
=
values
&&
_
.
clone
(
values
)
||
{}
// add all passed values to the dao and store the attribute names in this.attributes
if
(
options
.
isNewRecord
)
{
if
(
options
.
isNewRecord
)
{
if
(
this
.
hasDefaultValues
)
{
if
(
this
.
hasDefaultValues
)
{
...
@@ -644,30 +643,22 @@ module.exports = (function() {
...
@@ -644,30 +643,22 @@ module.exports = (function() {
}
}
if
(
this
.
__options
.
timestamps
)
{
if
(
this
.
__options
.
timestamps
)
{
if
(
!
this
.
defaultValues
[
this
.
_timestampAttributes
.
createdAt
])
{
if
(
defaults
[
this
.
_timestampAttributes
.
createdAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
createdAt
]
=
Utils
.
now
(
this
.
sequelize
.
options
.
dialect
)
this
.
dataValues
[
this
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
createdAt
]);
}
else
{
this
.
dataValues
[
this
.
_timestampAttributes
.
createdAt
]
=
defaults
[
this
.
_timestampAttributes
.
createdAt
];
delete
defaults
[
this
.
_timestampAttributes
.
createdAt
];
delete
defaults
[
this
.
_timestampAttributes
.
createdAt
];
}
}
if
(
!
this
.
defaultValues
[
this
.
_timestampAttributes
.
updatedAt
])
{
if
(
defaults
[
this
.
_timestampAttributes
.
updatedAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
updatedAt
]
=
Utils
.
now
(
this
.
sequelize
.
options
.
dialect
)
this
.
dataValues
[
this
.
_timestampAttributes
.
updatedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
updatedAt
]);
}
else
{
this
.
dataValues
[
this
.
_timestampAttributes
.
updatedAt
]
=
defaults
[
this
.
_timestampAttributes
.
updatedAt
];
delete
defaults
[
this
.
_timestampAttributes
.
updatedAt
];
delete
defaults
[
this
.
_timestampAttributes
.
updatedAt
];
}
}
if
(
this
.
__options
.
paranoid
&&
!
this
.
defaultValues
[
this
.
_timestampAttributes
.
deletedAt
])
{
if
(
defaults
[
this
.
_timestampAttributes
.
deletedAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
deletedAt
]
=
null
this
.
dataValues
[
this
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
deletedAt
]);
}
else
if
(
defaults
[
this
.
_timestampAttributes
.
deletedAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
deletedAt
]
=
defaults
[
this
.
_timestampAttributes
.
deletedAt
];
delete
defaults
[
this
.
_timestampAttributes
.
deletedAt
];
delete
defaults
[
this
.
_timestampAttributes
.
deletedAt
];
}
}
}
}
}
}
if
(
Object
.
keys
(
defaults
).
length
)
{
if
(
Object
.
keys
(
defaults
).
length
)
{
for
(
key
in
defaults
)
{
for
(
key
in
defaults
)
{
if
(
!
values
.
hasOwnProperty
(
key
))
{
if
(
!
values
.
hasOwnProperty
(
key
))
{
...
...
test/mysql/query-generator.test.js
View file @
0f1b00d
...
@@ -339,7 +339,7 @@ if (Support.dialectIsMySQL()) {
...
@@ -339,7 +339,7 @@ if (Support.dialectIsMySQL()) {
expectation
:
"INSERT INTO `myTable` (`name`,`foo`) VALUES ('foo',1),('bar',2);"
expectation
:
"INSERT INTO `myTable` (`name`,`foo`) VALUES ('foo',1),('bar',2);"
},
{
},
{
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
null
},
{
name
:
'bar'
,
nullValue
:
null
}]],
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
null
},
{
name
:
'bar'
,
nullValue
:
null
}]],
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',NULL);"
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',NULL
,NULL
);"
},
{
},
{
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
null
},
{
name
:
'bar'
,
foo
:
2
,
nullValue
:
null
}]],
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
null
},
{
name
:
'bar'
,
foo
:
2
,
nullValue
:
null
}]],
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);"
,
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);"
,
...
@@ -350,7 +350,7 @@ if (Support.dialectIsMySQL()) {
...
@@ -350,7 +350,7 @@ if (Support.dialectIsMySQL()) {
context
:
{
options
:
{
omitNull
:
true
}}
// Note: We don't honour this because it makes little sense when some rows may have nulls and others not
context
:
{
options
:
{
omitNull
:
true
}}
// Note: We don't honour this because it makes little sense when some rows may have nulls and others not
},
{
},
{
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
undefined
},
{
name
:
'bar'
,
foo
:
2
,
undefinedValue
:
undefined
}]],
arguments
:
[
'myTable'
,
[{
name
:
'foo'
,
foo
:
1
,
nullValue
:
undefined
},
{
name
:
'bar'
,
foo
:
2
,
undefinedValue
:
undefined
}]],
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`
) VALUES ('foo',1,NULL),('bar',2
,NULL);"
,
expectation
:
"INSERT INTO `myTable` (`name`,`foo`,`nullValue`
,`undefinedValue`) VALUES ('foo',1,NULL,NULL),('bar',2,NULL
,NULL);"
,
context
:
{
options
:
{
omitNull
:
true
}}
// Note: As above
context
:
{
options
:
{
omitNull
:
true
}}
// Note: As above
},
{
},
{
arguments
:
[
'myTable'
,
[{
name
:
"foo"
,
value
:
true
},
{
name
:
'bar'
,
value
:
false
}]],
arguments
:
[
'myTable'
,
[{
name
:
"foo"
,
value
:
true
},
{
name
:
'bar'
,
value
:
false
}]],
...
...
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