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 45503e7d
authored
Feb 12, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
[merge]
2 parents
9ee88b92
2525b46e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
134 additions
and
127 deletions
lib/associations/belongs-to.js
lib/associations/has-many-double-linked.js
lib/associations/has-many-single-linked.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/dao-factory.js
lib/dao-validator.js
lib/dao.js
lib/dialects/abstract/query-generator.js
lib/dialects/abstract/query.js
lib/dialects/postgres/query.js
lib/query-interface.js
test/associations/belongs-to.test.js
test/associations/has-many.test.js
test/associations/has-one.test.js
test/dao-factory/find.test.js
test/sequelize.test.js
lib/associations/belongs-to.js
View file @
45503e7
...
@@ -85,7 +85,7 @@ module.exports = (function() {
...
@@ -85,7 +85,7 @@ module.exports = (function() {
var
self
=
this
var
self
=
this
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
,
options
)
{
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
,
options
)
{
var
primaryKeys
=
!!
associatedObject
&&
!!
associatedObject
.
daoFactory
?
Object
.
keys
(
associatedObject
.
daoFactory
.
primaryKeys
)
:
[]
var
primaryKeys
=
!!
associatedObject
&&
!!
associatedObject
.
Model
?
Object
.
keys
(
associatedObject
.
Model
.
primaryKeys
)
:
[]
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
this
[
self
.
identifier
]
=
associatedObject
?
associatedObject
[
primaryKey
]
:
null
this
[
self
.
identifier
]
=
associatedObject
?
associatedObject
[
primaryKey
]
:
null
...
...
lib/associations/has-many-double-linked.js
View file @
45503e7
...
@@ -23,7 +23,7 @@ module.exports = (function() {
...
@@ -23,7 +23,7 @@ module.exports = (function() {
,
targetAssociation
=
self
.
association
.
targetAssociation
,
targetAssociation
=
self
.
association
.
targetAssociation
//fully qualify
//fully qualify
var
instancePrimaryKeys
=
Object
.
keys
(
self
.
instance
.
daoFactory
.
primaryKeys
)
var
instancePrimaryKeys
=
Object
.
keys
(
self
.
instance
.
Model
.
primaryKeys
)
,
instancePrimaryKey
=
instancePrimaryKeys
.
length
>
0
?
instancePrimaryKeys
[
0
]
:
'id'
,
instancePrimaryKey
=
instancePrimaryKeys
.
length
>
0
?
instancePrimaryKeys
[
0
]
:
'id'
where
[
through
.
tableName
+
"."
+
self
.
association
.
identifier
]
=
self
.
instance
[
instancePrimaryKey
]
where
[
through
.
tableName
+
"."
+
self
.
association
.
identifier
]
=
self
.
instance
[
instancePrimaryKey
]
...
...
lib/associations/has-many-single-linked.js
View file @
45503e7
...
@@ -32,7 +32,7 @@ module.exports = (function() {
...
@@ -32,7 +32,7 @@ module.exports = (function() {
HasManySingleLinked
.
prototype
.
injectSetter
=
function
(
emitter
,
oldAssociations
,
newAssociations
,
defaultAttributes
)
{
HasManySingleLinked
.
prototype
.
injectSetter
=
function
(
emitter
,
oldAssociations
,
newAssociations
,
defaultAttributes
)
{
var
self
=
this
var
self
=
this
,
associationKeys
=
Object
.
keys
((
oldAssociations
[
0
]
||
newAssociations
[
0
]
||
{
daoFactory
:
{
primaryKeys
:
{}}}).
daoFactory
.
primaryKeys
||
{})
,
associationKeys
=
Object
.
keys
((
oldAssociations
[
0
]
||
newAssociations
[
0
]
||
{
Model
:
{
primaryKeys
:
{}}}).
Model
.
primaryKeys
||
{})
,
associationKey
=
(
associationKeys
.
length
===
1
)
?
associationKeys
[
0
]
:
'id'
,
associationKey
=
(
associationKeys
.
length
===
1
)
?
associationKeys
[
0
]
:
'id'
,
chainer
=
new
Utils
.
QueryChainer
()
,
chainer
=
new
Utils
.
QueryChainer
()
,
options
=
{}
,
options
=
{}
...
@@ -77,7 +77,7 @@ module.exports = (function() {
...
@@ -77,7 +77,7 @@ module.exports = (function() {
if
(
unassociatedObjects
.
length
>
0
)
{
if
(
unassociatedObjects
.
length
>
0
)
{
// For the self.instance
// For the self.instance
var
pkeys
=
Object
.
keys
(
self
.
instance
.
daoFactory
.
primaryKeys
)
var
pkeys
=
Object
.
keys
(
self
.
instance
.
Model
.
primaryKeys
)
,
pkey
=
pkeys
.
length
===
1
?
pkeys
[
0
]
:
'id'
,
pkey
=
pkeys
.
length
===
1
?
pkeys
[
0
]
:
'id'
// For chainer
// For chainer
,
primaryKeys
=
Object
.
keys
(
this
.
__factory
.
target
.
primaryKeys
)
,
primaryKeys
=
Object
.
keys
(
this
.
__factory
.
target
.
primaryKeys
)
...
@@ -109,7 +109,7 @@ module.exports = (function() {
...
@@ -109,7 +109,7 @@ module.exports = (function() {
}
}
HasManySingleLinked
.
prototype
.
injectAdder
=
function
(
emitterProxy
,
newAssociation
,
additionalAttributes
)
{
HasManySingleLinked
.
prototype
.
injectAdder
=
function
(
emitterProxy
,
newAssociation
,
additionalAttributes
)
{
var
primaryKeys
=
Object
.
keys
(
this
.
instance
.
daoFactory
.
primaryKeys
)
var
primaryKeys
=
Object
.
keys
(
this
.
instance
.
Model
.
primaryKeys
)
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
options
=
{}
,
options
=
{}
...
...
lib/associations/has-many.js
View file @
45503e7
...
@@ -273,12 +273,12 @@ module.exports = (function() {
...
@@ -273,12 +273,12 @@ module.exports = (function() {
obj
[
this
.
accessors
.
add
]
=
function
(
newAssociatedObject
,
additionalAttributes
)
{
obj
[
this
.
accessors
.
add
]
=
function
(
newAssociatedObject
,
additionalAttributes
)
{
var
instance
=
this
var
instance
=
this
,
primaryKeys
=
Object
.
keys
(
newAssociatedObject
.
daoFactory
.
primaryKeys
||
{})
,
primaryKeys
=
Object
.
keys
(
newAssociatedObject
.
Model
.
primaryKeys
||
{})
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
where
=
{}
,
where
=
{}
where
[
newAssociatedObject
.
daoFactory
.
tableName
+
'.'
+
primaryKey
]
=
newAssociatedObject
[
primaryKey
]
where
[
newAssociatedObject
.
Model
.
tableName
+
'.'
+
primaryKey
]
=
newAssociatedObject
[
primaryKey
]
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
instance
[
self
.
accessors
.
get
]({
where
:
where
})
instance
[
self
.
accessors
.
get
]({
where
:
where
})
.
proxy
(
emitter
,
{
events
:
[
'error'
,
'sql'
]})
.
proxy
(
emitter
,
{
events
:
[
'error'
,
'sql'
]})
...
...
lib/associations/has-one.js
View file @
45503e7
...
@@ -57,7 +57,7 @@ module.exports = (function() {
...
@@ -57,7 +57,7 @@ module.exports = (function() {
,
smart
,
smart
obj
[
this
.
accessors
.
get
]
=
function
(
params
)
{
obj
[
this
.
accessors
.
get
]
=
function
(
params
)
{
var
primaryKeys
=
Object
.
keys
(
this
.
daoFactory
.
primaryKeys
)
var
primaryKeys
=
Object
.
keys
(
this
.
Model
.
primaryKeys
)
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
where
=
{}
,
where
=
{}
,
id
=
this
[
primaryKey
]
||
this
.
id
,
id
=
this
[
primaryKey
]
||
this
.
id
...
@@ -94,7 +94,7 @@ module.exports = (function() {
...
@@ -94,7 +94,7 @@ module.exports = (function() {
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
,
options
)
{
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
,
options
)
{
var
instance
=
this
var
instance
=
this
,
instanceKeys
=
Object
.
keys
(
instance
.
daoFactory
.
primaryKeys
)
,
instanceKeys
=
Object
.
keys
(
instance
.
Model
.
primaryKeys
)
,
instanceKey
=
instanceKeys
.
length
===
1
?
instanceKeys
[
0
]
:
'id'
,
instanceKey
=
instanceKeys
.
length
===
1
?
instanceKeys
[
0
]
:
'id'
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
...
lib/dao-factory.js
View file @
45503e7
...
@@ -120,72 +120,73 @@ module.exports = (function() {
...
@@ -120,72 +120,73 @@ module.exports = (function() {
this
.
primaryKeys
=
{}
this
.
primaryKeys
=
{}
self
.
options
.
uniqueKeys
=
{}
self
.
options
.
uniqueKeys
=
{}
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
columnValues
,
columnName
)
{
// Setup names of timestamp attributes
if
(
columnValues
.
hasOwnProperty
(
'unique'
)
&&
columnValues
.
unique
!==
true
&&
columnValues
.
unique
!==
false
)
{
this
.
_timestampAttributes
=
{}
var
idxName
=
columnValues
.
unique
if
(
this
.
options
.
timestamps
)
{
if
(
typeof
columnValues
.
unique
===
"object"
)
{
if
(
this
.
options
.
createdAt
)
{
idxName
=
columnValues
.
unique
.
name
this
.
_timestampAttributes
.
createdAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
updatedAt
)
{
this
.
_timestampAttributes
.
updatedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
paranoid
&&
this
.
options
.
deletedAt
)
{
this
.
_timestampAttributes
.
deletedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
}
}
// Identify primary and unique attributes
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
options
,
attribute
)
{
if
(
options
.
hasOwnProperty
(
'unique'
)
&&
options
.
unique
!==
true
&&
options
.
unique
!==
false
)
{
var
idxName
=
options
.
unique
if
(
typeof
options
.
unique
===
"object"
)
{
idxName
=
options
.
unique
.
name
}
}
self
.
options
.
uniqueKeys
[
idxName
]
=
self
.
options
.
uniqueKeys
[
idxName
]
||
{
fields
:
[],
msg
:
null
}
self
.
options
.
uniqueKeys
[
idxName
]
=
self
.
options
.
uniqueKeys
[
idxName
]
||
{
fields
:
[],
msg
:
null
}
self
.
options
.
uniqueKeys
[
idxName
].
fields
.
push
(
columnNam
e
)
self
.
options
.
uniqueKeys
[
idxName
].
fields
.
push
(
attribut
e
)
self
.
options
.
uniqueKeys
[
idxName
].
msg
=
self
.
options
.
uniqueKeys
[
idxName
].
msg
||
columnValue
s
.
unique
.
msg
||
null
self
.
options
.
uniqueKeys
[
idxName
].
msg
=
self
.
options
.
uniqueKeys
[
idxName
].
msg
||
option
s
.
unique
.
msg
||
null
}
}
})
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
if
(
options
.
primaryKey
===
true
)
{
if
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
)
{
self
.
primaryKeys
[
attribute
]
=
self
.
attributes
[
attribute
]
self
.
primaryKeys
[
attributeName
]
=
dataTypeString
}
}
})
})
// Add head and tail default attributes (id, timestamps)
addDefaultAttributes
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
findAutoIncrementField
.
call
(
this
)
// Primary key convenience variables
this
.
primaryKeyAttributes
=
Object
.
keys
(
this
.
primaryKeys
)
this
.
primaryKeyAttributes
=
Object
.
keys
(
this
.
primaryKeys
)
this
.
primaryKeyAttribute
=
this
.
primaryKeyAttributes
[
0
]
this
.
primaryKeyCount
=
this
.
primaryKeyAttributes
.
length
this
.
primaryKeyCount
=
this
.
primaryKeyAttributes
.
length
this
.
options
.
hasPrimaryKeys
=
this
.
hasPrimaryKeys
=
this
.
primaryKeyCount
>
0
this
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
=
this
.
hasPrimaryKeys
=
this
.
primaryKeyCount
>
0
this
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
})
if
(
typeof
this
.
options
.
defaultScope
===
"object"
)
{
if
(
typeof
this
.
options
.
defaultScope
===
"object"
)
{
Utils
.
injectScope
.
call
(
this
,
this
.
options
.
defaultScope
)
Utils
.
injectScope
.
call
(
this
,
this
.
options
.
defaultScope
)
}
}
// DAO prototype
// DAO prototype
// WTF ... ?
this
.
DAO
=
function
()
{
this
.
DAO
=
function
()
{
DAO
.
apply
(
this
,
arguments
);
DAO
.
apply
(
this
,
arguments
);
}
}
Util
.
inherits
(
this
.
DAO
,
DAO
);
Util
.
inherits
(
this
.
DAO
,
DAO
);
this
.
_timestampAttributes
=
{}
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
createdAt
)
{
this
.
_timestampAttributes
.
createdAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
updatedAt
)
{
this
.
_timestampAttributes
.
updatedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
paranoid
&&
this
.
options
.
deletedAt
)
{
this
.
_timestampAttributes
.
deletedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
}
this
.
DAO
.
prototype
.
_readOnlyAttributes
=
Object
.
keys
(
this
.
_timestampAttributes
)
this
.
_readOnlyAttributes
=
Object
.
keys
(
this
.
_timestampAttributes
)
}
this
.
_hasReadOnlyAttributes
=
this
.
_readOnlyAttributes
&&
this
.
_readOnlyAttributes
.
length
this
.
_isReadOnlyAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
this
.
DAO
.
prototype
.
_hasReadOnlyAttributes
=
this
.
DAO
.
prototype
.
_readOnlyAttributes
&&
this
.
DAO
.
prototype
.
_readOnlyAttributes
.
length
return
self
.
_hasReadOnlyAttributes
&&
self
.
_readOnlyAttributes
.
indexOf
(
key
)
!==
-
1
this
.
DAO
.
prototype
.
_isReadOnlyAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
DAO
.
prototype
.
_hasReadOnlyAttributes
&&
self
.
DAO
.
prototype
.
_readOnlyAttributes
.
indexOf
(
key
)
!==
-
1
})
})
addDefaultAttributes
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
findAutoIncrementField
.
call
(
this
)
this
.
DAO
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
DAO
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
DAO
.
prototype
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
this
.
DAO
.
prototype
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
&&
key
!==
'id'
})
if
(
this
.
options
.
instanceMethods
)
{
if
(
this
.
options
.
instanceMethods
)
{
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
,
function
(
fct
,
name
)
{
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
,
function
(
fct
,
name
)
{
self
.
DAO
.
prototype
[
name
]
=
fct
self
.
DAO
.
prototype
[
name
]
=
fct
...
@@ -194,20 +195,20 @@ module.exports = (function() {
...
@@ -194,20 +195,20 @@ module.exports = (function() {
this
.
refreshAttributes
();
this
.
refreshAttributes
();
this
.
DAO
.
prototype
.
booleanValu
es
=
[]
this
.
_booleanAttribut
es
=
[]
this
.
DAO
.
prototype
.
dateAttributes
=
[]
this
.
_
dateAttributes
=
[]
this
.
DAO
.
prototype
.
defaultValues
=
{}
this
.
_
defaultValues
=
{}
this
.
DAO
.
prototype
.
validators
=
{}
this
.
DAO
.
prototype
.
validators
=
{}
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
self
.
DAO
.
prototype
.
booleanValu
es
.
push
(
name
);
self
.
_booleanAttribut
es
.
push
(
name
);
}
}
if
(((
definition
===
DataTypes
.
DATE
)
||
(
definition
.
type
===
DataTypes
.
DATE
)
||
(
definition
.
originalType
===
DataTypes
.
DATE
)))
{
if
(((
definition
===
DataTypes
.
DATE
)
||
(
definition
.
type
===
DataTypes
.
DATE
)
||
(
definition
.
originalType
===
DataTypes
.
DATE
)))
{
self
.
DAO
.
prototype
.
dateAttributes
.
push
(
name
);
self
.
_
dateAttributes
.
push
(
name
);
}
}
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
self
.
DAO
.
prototype
.
defaultValues
[
name
]
=
Utils
.
_
.
partial
(
self
.
_
defaultValues
[
name
]
=
Utils
.
_
.
partial
(
Utils
.
toDefaultValue
,
definition
.
defaultValue
)
Utils
.
toDefaultValue
,
definition
.
defaultValue
)
}
}
...
@@ -216,21 +217,19 @@ module.exports = (function() {
...
@@ -216,21 +217,19 @@ module.exports = (function() {
}
}
})
})
this
.
DAO
.
prototype
.
_hasBooleanAttributes
=
!!
this
.
DAO
.
prototype
.
booleanValu
es
.
length
this
.
_hasBooleanAttributes
=
!!
this
.
_booleanAttribut
es
.
length
this
.
DAO
.
prototype
.
_isBooleanAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
this
.
_isBooleanAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
DAO
.
prototype
.
booleanValu
es
.
indexOf
(
key
)
!==
-
1
return
self
.
_booleanAttribut
es
.
indexOf
(
key
)
!==
-
1
})
})
this
.
DAO
.
prototype
.
_hasDateAttributes
=
!!
this
.
DAO
.
prototype
.
dateAttributes
.
length
this
.
_hasDateAttributes
=
!!
this
.
_
dateAttributes
.
length
this
.
DAO
.
prototype
.
_isDateAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
this
.
_isDateAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
DAO
.
prototype
.
dateAttributes
.
indexOf
(
key
)
!==
-
1
return
self
.
_
dateAttributes
.
indexOf
(
key
)
!==
-
1
})
})
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
Model
=
this
this
.
DAO
.
prototype
.
daoFactory
=
this
this
.
DAO
.
prototype
.
Model
=
this
this
.
_hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
_defaultValues
)
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
this
.
DAO
.
prototype
.
daoFactoryName
=
this
.
name
return
this
return
this
}
}
...
@@ -1276,7 +1275,11 @@ module.exports = (function() {
...
@@ -1276,7 +1275,11 @@ module.exports = (function() {
var
addDefaultAttributes
=
function
()
{
var
addDefaultAttributes
=
function
()
{
var
self
=
this
var
self
=
this
,
tail
=
{}
,
tail
=
{}
,
head
=
{
,
head
=
{}
// Add id if no primary key was manually added to definition
if
(
!
Object
.
keys
(
this
.
primaryKeys
).
length
)
{
head
=
{
id
:
{
id
:
{
type
:
DataTypes
.
INTEGER
,
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
allowNull
:
false
,
...
@@ -1285,9 +1288,6 @@ module.exports = (function() {
...
@@ -1285,9 +1288,6 @@ module.exports = (function() {
_autoGenerated
:
true
_autoGenerated
:
true
}
}
}
}
if
(
this
.
hasPrimaryKeys
)
{
head
=
{}
}
}
if
(
this
.
_timestampAttributes
.
createdAt
)
{
if
(
this
.
_timestampAttributes
.
createdAt
)
{
...
@@ -1316,6 +1316,10 @@ module.exports = (function() {
...
@@ -1316,6 +1316,10 @@ module.exports = (function() {
self
.
rawAttributes
[
attr
]
=
value
self
.
rawAttributes
[
attr
]
=
value
}
}
})
})
if
(
!
Object
.
keys
(
this
.
primaryKeys
).
length
)
{
self
.
primaryKeys
[
'id'
]
=
self
.
attributes
[
'id'
]
}
}
}
var
findAutoIncrementField
=
function
()
{
var
findAutoIncrementField
=
function
()
{
...
@@ -1344,8 +1348,12 @@ module.exports = (function() {
...
@@ -1344,8 +1348,12 @@ module.exports = (function() {
options
.
includeNames
.
push
(
include
.
as
)
options
.
includeNames
.
push
(
include
.
as
)
options
.
includeNames
.
push
(
include
.
as
.
substr
(
0
,
1
).
toLowerCase
()
+
include
.
as
.
substr
(
1
))
options
.
includeNames
.
push
(
include
.
as
.
substr
(
0
,
1
).
toLowerCase
()
+
include
.
as
.
substr
(
1
))
if
(
include
.
association
.
isMultiAssociation
||
include
.
hasMultiAssociation
)
options
.
hasMultiAssociation
=
true
if
(
include
.
association
.
isMultiAssociation
||
include
.
hasMultiAssociation
)
{
if
(
include
.
association
.
isSingleAssociation
||
include
.
hasSingleAssociation
)
options
.
hasSingleAssociation
=
true
options
.
hasMultiAssociation
=
true
}
if
(
include
.
association
.
isSingleAssociation
||
include
.
hasSingleAssociation
)
{
options
.
hasSingleAssociation
=
true
}
options
.
hasIncludeWhere
=
options
.
hasIncludeWhere
||
include
.
hasIncludeWhere
||
!!
include
.
where
options
.
hasIncludeWhere
=
options
.
hasIncludeWhere
||
include
.
hasIncludeWhere
||
!!
include
.
where
options
.
hasIncludeRequired
=
options
.
hasIncludeRequired
||
include
.
hasIncludeRequired
||
!!
include
.
required
options
.
hasIncludeRequired
=
options
.
hasIncludeRequired
||
include
.
hasIncludeRequired
||
!!
include
.
required
...
@@ -1378,8 +1386,8 @@ module.exports = (function() {
...
@@ -1378,8 +1386,8 @@ module.exports = (function() {
var
primaryKeys
;
var
primaryKeys
;
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
primaryKeys
=
[]
primaryKeys
=
[]
for
(
var
field
_name
in
include
.
daoFactory
.
primaryKeys
)
{
for
(
var
field
in
include
.
daoFactory
.
primaryKeys
)
{
primaryKeys
.
push
(
field
_name
)
primaryKeys
.
push
(
field
)
}
}
}
else
{
}
else
{
primaryKeys
=
[
'id'
]
primaryKeys
=
[
'id'
]
...
@@ -1393,7 +1401,7 @@ module.exports = (function() {
...
@@ -1393,7 +1401,7 @@ module.exports = (function() {
if
(
include
.
_pseudo
)
return
include
if
(
include
.
_pseudo
)
return
include
// check if the current daoFactory is actually associated with the passed daoFactory - or it's a pseudo include
// check if the current daoFactory is actually associated with the passed daoFactory - or it's a pseudo include
var
association
=
parent
.
getAssociation
(
include
.
daoFactory
,
include
.
as
)
var
association
=
parent
.
getAssociation
(
include
.
daoFactory
,
include
.
as
)
if
(
association
)
{
if
(
association
)
{
include
.
association
=
association
include
.
association
=
association
include
.
as
=
association
.
as
include
.
as
=
association
.
as
...
...
lib/dao-validator.js
View file @
45503e7
...
@@ -2,11 +2,11 @@ var Validator = require("validator")
...
@@ -2,11 +2,11 @@ var Validator = require("validator")
,
Utils
=
require
(
"./utils"
)
,
Utils
=
require
(
"./utils"
)
,
sequelizeError
=
require
(
"./errors"
)
,
sequelizeError
=
require
(
"./errors"
)
var
DaoValidator
=
module
.
exports
=
function
(
model
,
options
)
{
var
DaoValidator
=
module
.
exports
=
function
(
model
Instance
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
options
.
skip
=
options
.
skip
||
[]
options
.
skip
=
options
.
skip
||
[]
this
.
model
=
model
this
.
model
Instance
=
modelInstance
this
.
chainer
=
new
Utils
.
QueryChainer
()
this
.
chainer
=
new
Utils
.
QueryChainer
()
this
.
options
=
options
this
.
options
=
options
}
}
...
@@ -44,10 +44,9 @@ DaoValidator.prototype.validate = function() {
...
@@ -44,10 +44,9 @@ DaoValidator.prototype.validate = function() {
DaoValidator
.
prototype
.
hookValidate
=
function
()
{
DaoValidator
.
prototype
.
hookValidate
=
function
()
{
var
self
=
this
var
self
=
this
,
errors
=
{}
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
model
.
daoFactory
.
runHooks
(
'beforeValidate'
,
self
.
model
,
function
(
err
)
{
self
.
model
Instance
.
Model
.
runHooks
(
'beforeValidate'
,
self
.
modelInstance
,
function
(
err
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
return
emitter
.
emit
(
'error'
,
err
)
return
emitter
.
emit
(
'error'
,
err
)
}
}
...
@@ -57,12 +56,12 @@ DaoValidator.prototype.hookValidate = function() {
...
@@ -57,12 +56,12 @@ DaoValidator.prototype.hookValidate = function() {
return
emitter
.
emit
(
'error'
,
error
)
return
emitter
.
emit
(
'error'
,
error
)
}
}
self
.
model
.
daoFactory
.
runHooks
(
'afterValidate'
,
self
.
model
,
function
(
err
)
{
self
.
model
Instance
.
Model
.
runHooks
(
'afterValidate'
,
self
.
modelInstance
,
function
(
err
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
return
emitter
.
emit
(
'error'
,
err
)
return
emitter
.
emit
(
'error'
,
err
)
}
}
emitter
.
emit
(
'success'
,
self
.
model
)
emitter
.
emit
(
'success'
,
self
.
modelInstance
)
})
})
})
})
})
})
...
@@ -71,7 +70,7 @@ DaoValidator.prototype.hookValidate = function() {
...
@@ -71,7 +70,7 @@ DaoValidator.prototype.hookValidate = function() {
// private
// private
var
validateModel
=
function
()
{
var
validateModel
=
function
()
{
Utils
.
_
.
each
(
this
.
model
.
__options
.
validate
,
function
(
_validator
,
validatorType
)
{
Utils
.
_
.
each
(
this
.
model
Instance
.
__options
.
validate
,
function
(
_validator
,
validatorType
)
{
var
validator
=
prepareValidationOfAttribute
.
call
(
this
,
undefined
,
_validator
,
validatorType
,
{
omitValue
:
true
})
var
validator
=
prepareValidationOfAttribute
.
call
(
this
,
undefined
,
_validator
,
validatorType
,
{
omitValue
:
true
})
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
@@ -99,12 +98,12 @@ var validateAttributes = function() {
...
@@ -99,12 +98,12 @@ var validateAttributes = function() {
var
self
=
this
var
self
=
this
,
errors
=
{}
,
errors
=
{}
Utils
.
_
.
each
(
this
.
model
.
rawAttributes
,
function
(
rawAttribute
,
field
)
{
Utils
.
_
.
each
(
this
.
model
Instance
.
rawAttributes
,
function
(
rawAttribute
,
field
)
{
var
value
=
self
.
model
.
dataValues
[
field
]
var
value
=
self
.
model
Instance
.
dataValues
[
field
]
,
hasAllowedNull
=
((
rawAttribute
===
undefined
||
rawAttribute
.
allowNull
===
true
)
&&
((
value
===
null
)
||
(
value
===
undefined
)))
,
hasAllowedNull
=
((
rawAttribute
===
undefined
||
rawAttribute
.
allowNull
===
true
)
&&
((
value
===
null
)
||
(
value
===
undefined
)))
,
isSkipped
=
self
.
options
.
skip
.
length
>
0
&&
self
.
options
.
skip
.
indexOf
(
field
)
!==
-
1
,
isSkipped
=
self
.
options
.
skip
.
length
>
0
&&
self
.
options
.
skip
.
indexOf
(
field
)
!==
-
1
if
(
self
.
model
.
validators
.
hasOwnProperty
(
field
)
&&
!
hasAllowedNull
&&
!
isSkipped
)
{
if
(
self
.
model
Instance
.
validators
.
hasOwnProperty
(
field
)
&&
!
hasAllowedNull
&&
!
isSkipped
)
{
errors
=
Utils
.
_
.
merge
(
errors
,
validateAttribute
.
call
(
self
,
value
,
field
))
errors
=
Utils
.
_
.
merge
(
errors
,
validateAttribute
.
call
(
self
,
value
,
field
))
}
}
})
})
...
@@ -114,7 +113,7 @@ var validateAttributes = function() {
...
@@ -114,7 +113,7 @@ var validateAttributes = function() {
var
validateAttribute
=
function
(
value
,
field
)
{
var
validateAttribute
=
function
(
value
,
field
)
{
// for each validator
// for each validator
Utils
.
_
.
each
(
this
.
model
.
validators
[
field
],
function
(
details
,
validatorType
)
{
Utils
.
_
.
each
(
this
.
model
Instance
.
validators
[
field
],
function
(
details
,
validatorType
)
{
var
validator
=
prepareValidationOfAttribute
.
call
(
this
,
value
,
details
,
validatorType
)
var
validator
=
prepareValidationOfAttribute
.
call
(
this
,
value
,
details
,
validatorType
)
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
@@ -162,7 +161,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
...
@@ -162,7 +161,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
}
}
try
{
try
{
details
.
apply
(
this
.
model
,
callArgs
)
details
.
apply
(
this
.
model
Instance
,
callArgs
)
}
catch
(
ex
)
{
}
catch
(
ex
)
{
return
next
(
ex
)
return
next
(
ex
)
}
}
...
...
lib/dao.js
View file @
45503e7
This diff is collapsed.
Click to expand it.
lib/dialects/abstract/query-generator.js
View file @
45503e7
...
@@ -512,7 +512,7 @@ module.exports = (function() {
...
@@ -512,7 +512,7 @@ module.exports = (function() {
- offset -> An offset value to start from. Only useable with limit!
- offset -> An offset value to start from. Only useable with limit!
*/
*/
selectQuery
:
function
(
tableName
,
options
,
factory
)
{
selectQuery
:
function
(
tableName
,
options
,
Model
)
{
// Enter and change at your own peril -- Mick Hansen
// Enter and change at your own peril -- Mick Hansen
options
=
options
||
{}
options
=
options
||
{}
...
@@ -536,7 +536,7 @@ module.exports = (function() {
...
@@ -536,7 +536,7 @@ module.exports = (function() {
}.
bind
(
this
)).
join
(
", "
)
}.
bind
(
this
)).
join
(
", "
)
if
(
subQuery
&&
mainAttributes
)
{
if
(
subQuery
&&
mainAttributes
)
{
mainAttributes
=
mainAttributes
.
concat
(
factory
.
hasPrimaryKeys
?
factory
.
primaryKeyAttributes
:
[
'id'
]
)
mainAttributes
=
mainAttributes
.
concat
(
Model
.
primaryKeyAttributes
)
}
}
// Escape attributes
// Escape attributes
...
@@ -616,16 +616,16 @@ module.exports = (function() {
...
@@ -616,16 +616,16 @@ module.exports = (function() {
,
throughAttributes
=
through
.
attributes
.
map
(
function
(
attr
)
{
,
throughAttributes
=
through
.
attributes
.
map
(
function
(
attr
)
{
return
self
.
quoteIdentifier
(
throughAs
)
+
"."
+
self
.
quoteIdentifier
(
attr
)
+
" AS "
+
self
.
quoteIdentifier
(
throughAs
+
"."
+
attr
)
return
self
.
quoteIdentifier
(
throughAs
)
+
"."
+
self
.
quoteIdentifier
(
attr
)
+
" AS "
+
self
.
quoteIdentifier
(
throughAs
+
"."
+
attr
)
})
})
,
primaryKeysSource
=
Object
.
keys
(
association
.
source
.
primaryKeys
)
,
primaryKeysSource
=
association
.
source
.
primaryKeyAttributes
,
tableSource
=
parentTable
,
tableSource
=
parentTable
,
identSource
=
association
.
identifier
,
identSource
=
association
.
identifier
,
attrSource
=
((
!
association
.
source
.
hasPrimaryKeys
||
primaryKeysSource
.
length
!==
1
)
?
'id'
:
primaryKeysSource
[
0
])
,
attrSource
=
primaryKeysSource
[
0
]
,
where
,
where
,
primaryKeysTarget
=
Object
.
keys
(
association
.
target
.
primaryKeys
)
,
primaryKeysTarget
=
association
.
target
.
primaryKeyAttributes
,
tableTarget
=
as
,
tableTarget
=
as
,
identTarget
=
association
.
foreignIdentifier
,
identTarget
=
association
.
foreignIdentifier
,
attrTarget
=
((
!
include
.
association
.
target
.
hasPrimaryKeys
||
primaryKeysTarget
.
length
!==
1
)
?
'id'
:
primaryKeysTarget
[
0
])
,
attrTarget
=
primaryKeysTarget
[
0
]
,
sourceJoinOn
,
sourceJoinOn
,
targetJoinOn
,
targetJoinOn
...
@@ -673,10 +673,10 @@ module.exports = (function() {
...
@@ -673,10 +673,10 @@ module.exports = (function() {
}
}
}
}
}
else
{
}
else
{
var
primaryKeysLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
Object
.
keys
(
association
.
target
.
primaryKeys
)
:
Object
.
keys
(
include
.
association
.
source
.
primaryKeys
))
var
primaryKeysLeft
=
association
.
associationType
===
'BelongsTo'
?
association
.
target
.
primaryKeyAttributes
:
include
.
association
.
source
.
primaryKeyAttributes
,
tableLeft
=
((
association
.
associationType
===
'BelongsTo'
)
?
as
:
parentTable
)
,
tableLeft
=
association
.
associationType
===
'BelongsTo'
?
as
:
parentTable
,
attrLeft
=
((
primaryKeysLeft
.
length
!==
1
)
?
'id'
:
primaryKeysLeft
[
0
])
,
attrLeft
=
primaryKeysLeft
[
0
]
,
tableRight
=
((
association
.
associationType
===
'BelongsTo'
)
?
parentTable
:
as
)
,
tableRight
=
association
.
associationType
===
'BelongsTo'
?
parentTable
:
as
,
attrRight
=
association
.
identifier
,
attrRight
=
association
.
identifier
,
where
,
where
...
@@ -737,7 +737,7 @@ module.exports = (function() {
...
@@ -737,7 +737,7 @@ module.exports = (function() {
// Add WHERE to sub or main query
// Add WHERE to sub or main query
if
(
options
.
hasOwnProperty
(
'where'
))
{
if
(
options
.
hasOwnProperty
(
'where'
))
{
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
,
factory
,
options
)
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
,
Model
,
options
)
if
(
subQuery
)
{
if
(
subQuery
)
{
subQueryItems
.
push
(
" WHERE "
+
options
.
where
)
subQueryItems
.
push
(
" WHERE "
+
options
.
where
)
}
else
{
}
else
{
...
@@ -747,7 +747,7 @@ module.exports = (function() {
...
@@ -747,7 +747,7 @@ module.exports = (function() {
// Add GROUP BY to sub or main query
// Add GROUP BY to sub or main query
if
(
options
.
group
)
{
if
(
options
.
group
)
{
options
.
group
=
Array
.
isArray
(
options
.
group
)
?
options
.
group
.
map
(
function
(
t
)
{
return
this
.
quote
(
t
,
factory
)
}.
bind
(
this
)).
join
(
', '
)
:
options
.
group
options
.
group
=
Array
.
isArray
(
options
.
group
)
?
options
.
group
.
map
(
function
(
t
)
{
return
this
.
quote
(
t
,
Model
)
}.
bind
(
this
)).
join
(
', '
)
:
options
.
group
if
(
subQuery
)
{
if
(
subQuery
)
{
subQueryItems
.
push
(
" GROUP BY "
+
options
.
group
)
subQueryItems
.
push
(
" GROUP BY "
+
options
.
group
)
}
else
{
}
else
{
...
@@ -757,7 +757,7 @@ module.exports = (function() {
...
@@ -757,7 +757,7 @@ module.exports = (function() {
// Add HAVING to sub or main query
// Add HAVING to sub or main query
if
(
options
.
hasOwnProperty
(
'having'
))
{
if
(
options
.
hasOwnProperty
(
'having'
))
{
options
.
having
=
this
.
getWhereConditions
(
options
.
having
,
tableName
,
factory
,
options
,
false
)
options
.
having
=
this
.
getWhereConditions
(
options
.
having
,
tableName
,
Model
,
options
,
false
)
if
(
subQuery
)
{
if
(
subQuery
)
{
subQueryItems
.
push
(
" HAVING "
+
options
.
having
)
subQueryItems
.
push
(
" HAVING "
+
options
.
having
)
}
else
{
}
else
{
...
@@ -767,7 +767,7 @@ module.exports = (function() {
...
@@ -767,7 +767,7 @@ module.exports = (function() {
// Add ORDER to sub or main query
// Add ORDER to sub or main query
if
(
options
.
order
)
{
if
(
options
.
order
)
{
options
.
order
=
Array
.
isArray
(
options
.
order
)
?
options
.
order
.
map
(
function
(
t
)
{
return
this
.
quote
(
t
,
factory
)
}.
bind
(
this
)).
join
(
', '
)
:
options
.
order
options
.
order
=
Array
.
isArray
(
options
.
order
)
?
options
.
order
.
map
(
function
(
t
)
{
return
this
.
quote
(
t
,
Model
)
}.
bind
(
this
)).
join
(
', '
)
:
options
.
order
if
(
subQuery
)
{
if
(
subQuery
)
{
subQueryItems
.
push
(
" ORDER BY "
+
options
.
order
)
subQueryItems
.
push
(
" ORDER BY "
+
options
.
order
)
...
...
lib/dialects/abstract/query.js
View file @
45503e7
...
@@ -173,7 +173,7 @@ module.exports = (function() {
...
@@ -173,7 +173,7 @@ module.exports = (function() {
var
handleInsertQuery
=
function
(
results
,
metaData
)
{
var
handleInsertQuery
=
function
(
results
,
metaData
)
{
if
(
this
.
callee
)
{
if
(
this
.
callee
)
{
// add the inserted row id to the instance
// add the inserted row id to the instance
var
autoIncrementField
=
this
.
callee
.
__factory
.
autoIncrementField
var
autoIncrementField
=
this
.
callee
.
Model
.
autoIncrementField
,
id
=
null
,
id
=
null
id
=
id
||
(
results
&&
results
[
this
.
getInsertIdField
()])
id
=
id
||
(
results
&&
results
[
this
.
getInsertIdField
()])
...
...
lib/dialects/postgres/query.js
View file @
45503e7
...
@@ -137,7 +137,7 @@ module.exports = (function() {
...
@@ -137,7 +137,7 @@ module.exports = (function() {
for
(
var
key
in
rows
[
0
])
{
for
(
var
key
in
rows
[
0
])
{
if
(
rows
[
0
].
hasOwnProperty
(
key
))
{
if
(
rows
[
0
].
hasOwnProperty
(
key
))
{
var
record
=
rows
[
0
][
key
]
var
record
=
rows
[
0
][
key
]
if
(
!!
this
.
callee
.
daoFactory
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
]
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
.
type
&&
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
.
type
===
DataTypes
.
HSTORE
.
type
)
{
if
(
!!
this
.
callee
.
Model
&&
!!
this
.
callee
.
Model
.
rawAttributes
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
]
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
.
type
&&
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
.
type
===
DataTypes
.
HSTORE
.
type
)
{
record
=
hstore
.
parse
(
record
)
record
=
hstore
.
parse
(
record
)
}
}
this
.
callee
.
dataValues
[
key
]
=
record
this
.
callee
.
dataValues
[
key
]
=
record
...
@@ -152,7 +152,7 @@ module.exports = (function() {
...
@@ -152,7 +152,7 @@ module.exports = (function() {
for
(
var
key
in
rows
[
0
])
{
for
(
var
key
in
rows
[
0
])
{
if
(
rows
[
0
].
hasOwnProperty
(
key
))
{
if
(
rows
[
0
].
hasOwnProperty
(
key
))
{
var
record
=
rows
[
0
][
key
]
var
record
=
rows
[
0
][
key
]
if
(
!!
this
.
callee
.
daoFactory
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
]
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
&&
!!
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
.
type
&&
this
.
callee
.
daoFactory
.
rawAttributes
[
key
].
type
.
type
===
DataTypes
.
HSTORE
.
type
)
{
if
(
!!
this
.
callee
.
Model
&&
!!
this
.
callee
.
Model
.
rawAttributes
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
]
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
&&
!!
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
.
type
&&
this
.
callee
.
Model
.
rawAttributes
[
key
].
type
.
type
===
DataTypes
.
HSTORE
.
type
)
{
record
=
hstore
.
parse
(
record
)
record
=
hstore
.
parse
(
record
)
}
}
this
.
callee
.
dataValues
[
key
]
=
record
this
.
callee
.
dataValues
[
key
]
=
record
...
...
lib/query-interface.js
View file @
45503e7
...
@@ -504,7 +504,7 @@ module.exports = (function() {
...
@@ -504,7 +504,7 @@ module.exports = (function() {
}
}
QueryInterface
.
prototype
.
insert
=
function
(
dao
,
tableName
,
values
,
options
)
{
QueryInterface
.
prototype
.
insert
=
function
(
dao
,
tableName
,
values
,
options
)
{
var
sql
=
this
.
QueryGenerator
.
insertQuery
(
tableName
,
values
,
dao
.
daoFactory
.
rawAttributes
)
var
sql
=
this
.
QueryGenerator
.
insertQuery
(
tableName
,
values
,
dao
.
Model
.
rawAttributes
)
return
queryAndEmit
.
call
(
this
,
[
sql
,
dao
,
options
],
'insert'
,
{
return
queryAndEmit
.
call
(
this
,
[
sql
,
dao
,
options
],
'insert'
,
{
success
:
function
(
obj
)
{
obj
.
isNewRecord
=
false
}
success
:
function
(
obj
)
{
obj
.
isNewRecord
=
false
}
})
})
...
@@ -518,15 +518,15 @@ module.exports = (function() {
...
@@ -518,15 +518,15 @@ module.exports = (function() {
QueryInterface
.
prototype
.
update
=
function
(
dao
,
tableName
,
values
,
identifier
,
options
)
{
QueryInterface
.
prototype
.
update
=
function
(
dao
,
tableName
,
values
,
identifier
,
options
)
{
var
self
=
this
var
self
=
this
,
restrict
=
false
,
restrict
=
false
,
sql
=
self
.
QueryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
,
options
,
dao
.
daoFactory
.
rawAttributes
)
,
sql
=
self
.
QueryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
,
options
,
dao
.
Model
.
rawAttributes
)
// Check for a restrict field
// Check for a restrict field
if
(
!!
dao
.
daoFactory
&&
!!
dao
.
daoFactory
.
associations
)
{
if
(
!!
dao
.
Model
&&
!!
dao
.
Model
.
associations
)
{
var
keys
=
Object
.
keys
(
dao
.
daoFactory
.
associations
)
var
keys
=
Object
.
keys
(
dao
.
Model
.
associations
)
,
length
=
keys
.
length
,
length
=
keys
.
length
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
if
(
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
&&
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
onUpdate
&&
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
onUpdate
===
"restrict"
)
{
if
(
dao
.
Model
.
associations
[
keys
[
i
]].
options
&&
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
onUpdate
&&
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
onUpdate
===
"restrict"
)
{
restrict
=
true
restrict
=
true
}
}
}
}
...
@@ -581,20 +581,20 @@ module.exports = (function() {
...
@@ -581,20 +581,20 @@ module.exports = (function() {
var
self
=
this
var
self
=
this
,
restrict
=
false
,
restrict
=
false
,
cascades
=
[]
,
cascades
=
[]
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
null
,
dao
.
daoFactory
)
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
null
,
dao
.
Model
)
// Check for a restrict field
// Check for a restrict field
if
(
!!
dao
.
daoFactory
&&
!!
dao
.
daoFactory
.
associations
)
{
if
(
!!
dao
.
Model
&&
!!
dao
.
Model
.
associations
)
{
var
keys
=
Object
.
keys
(
dao
.
daoFactory
.
associations
)
var
keys
=
Object
.
keys
(
dao
.
Model
.
associations
)
,
length
=
keys
.
length
,
length
=
keys
.
length
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
if
(
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
&&
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
onDelete
)
{
if
(
dao
.
Model
.
associations
[
keys
[
i
]].
options
&&
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
onDelete
)
{
if
(
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
onDelete
===
"restrict"
)
{
if
(
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
onDelete
===
"restrict"
)
{
restrict
=
true
restrict
=
true
}
}
else
if
(
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
onDelete
===
"cascade"
&&
dao
.
daoFactory
.
associations
[
keys
[
i
]].
options
.
useHooks
===
true
)
{
else
if
(
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
onDelete
===
"cascade"
&&
dao
.
Model
.
associations
[
keys
[
i
]].
options
.
useHooks
===
true
)
{
cascades
[
cascades
.
length
]
=
dao
.
daoFactory
.
associations
[
keys
[
i
]].
accessors
.
get
cascades
[
cascades
.
length
]
=
dao
.
Model
.
associations
[
keys
[
i
]].
accessors
.
get
}
}
}
}
}
}
...
...
test/associations/belongs-to.test.js
View file @
45503e7
...
@@ -297,7 +297,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -297,7 +297,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
success
(
function
()
{
.
success
(
function
()
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
...
@@ -327,7 +327,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -327,7 +327,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
error
(
function
()
{
.
error
(
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
...
...
test/associations/has-many.test.js
View file @
45503e7
...
@@ -1389,7 +1389,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1389,7 +1389,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
success
(
function
()
{
.
success
(
function
()
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
...
@@ -1421,7 +1421,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1421,7 +1421,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
error
(
function
()
{
.
error
(
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
...
...
test/associations/has-one.test.js
View file @
45503e7
...
@@ -301,7 +301,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -301,7 +301,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
success
(
function
()
{
.
success
(
function
()
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
...
@@ -333,7 +333,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -333,7 +333,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
// the `UPDATE` query generated by `save()` uses `id` in the
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
__factory
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
error
(
function
()
{
.
error
(
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
...
...
test/dao-factory/find.test.js
View file @
45503e7
...
@@ -101,7 +101,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -101,7 +101,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'doesn\'t throw an error when entering in a non integer value'
,
function
(
done
)
{
x
it
(
'doesn\'t throw an error when entering in a non integer value'
,
function
(
done
)
{
this
.
User
.
find
(
'a string value'
).
success
(
function
(
user
)
{
this
.
User
.
find
(
'a string value'
).
success
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
null
expect
(
user
).
to
.
be
.
null
done
()
done
()
...
...
test/sequelize.test.js
View file @
45503e7
...
@@ -272,7 +272,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -272,7 +272,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
var
self
=
this
var
self
=
this
self
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
()
{
self
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
()
{
self
.
sequelize
.
query
(
"SELECT * FROM "
+
qq
(
self
.
User
.
tableName
)
+
";"
,
self
.
User
).
success
(
function
(
users
)
{
self
.
sequelize
.
query
(
"SELECT * FROM "
+
qq
(
self
.
User
.
tableName
)
+
";"
,
self
.
User
).
success
(
function
(
users
)
{
expect
(
users
[
0
].
__factory
).
to
.
equal
(
self
.
User
)
expect
(
users
[
0
].
Model
).
to
.
equal
(
self
.
User
)
done
()
done
()
})
})
})
})
...
...
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