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 63677587
authored
Jan 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more stuff
1 parent
74c6204a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
13 deletions
lib/dao-factory.js
lib/dao.js
test/dao-factory/create.test.js
test/include.test.js
lib/dao-factory.js
View file @
6367758
...
...
@@ -1186,7 +1186,9 @@ module.exports = (function() {
var
addDefaultAttributes
=
function
()
{
var
self
=
this
,
defaultAttributes
=
{
,
head
=
{}
,
tail
=
{}
,
head
=
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
...
...
@@ -1196,18 +1198,29 @@ module.exports = (function() {
}
if
(
this
.
hasPrimaryKeys
)
{
defaultAttributes
=
{}
head
=
{}
}
if
(
this
.
options
.
timestamps
)
{
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
if
(
this
.
options
.
paranoid
)
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
}
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
}
}
Utils
.
_
.
each
(
defaultAttributes
,
function
(
value
,
attr
)
{
var
existingAttributes
=
Utils
.
_
.
clone
(
self
.
rawAttributes
)
self
.
rawAttributes
=
{}
Utils
.
_
.
each
(
head
,
function
(
value
,
attr
)
{
self
.
rawAttributes
[
attr
]
=
value
})
Utils
.
_
.
each
(
existingAttributes
,
function
(
value
,
attr
)
{
self
.
rawAttributes
[
attr
]
=
value
})
Utils
.
_
.
each
(
tail
,
function
(
value
,
attr
)
{
if
(
Utils
.
_
.
isUndefined
(
self
.
rawAttributes
[
attr
]))
{
self
.
rawAttributes
[
attr
]
=
value
}
...
...
lib/dao.js
View file @
6367758
...
...
@@ -42,7 +42,7 @@ module.exports = (function() {
Object
.
defineProperty
(
DAO
.
prototype
,
'values'
,
{
get
:
function
()
{
return
this
.
dataValues
return
this
.
get
()
}
})
...
...
@@ -88,11 +88,15 @@ module.exports = (function() {
}
DAO
.
prototype
.
get
=
function
(
key
)
{
if
(
key
)
{
if
(
this
.
_customGetters
[
key
])
{
return
this
.
_customGetters
[
key
].
call
(
this
)
return
this
.
_customGetters
[
key
].
call
(
this
,
key
)
}
return
this
.
dataValues
[
key
]
}
return
this
.
dataValues
}
DAO
.
prototype
.
set
=
function
(
key
,
value
,
options
)
{
var
values
,
originalValue
...
...
@@ -126,7 +130,7 @@ module.exports = (function() {
// If not raw, and there's a customer setter
if
(
!
options
.
raw
&&
this
.
_customSetters
[
key
])
{
this
.
_customSetters
[
key
].
call
(
this
,
value
)
this
.
_customSetters
[
key
].
call
(
this
,
value
,
key
)
}
else
{
// Check if we have included models, and if this key matches the include model names/aliases
if
(
this
.
options
&&
this
.
options
.
include
&&
this
.
options
.
includeNames
.
indexOf
(
key
)
!==
-
1
)
{
...
...
@@ -606,7 +610,7 @@ module.exports = (function() {
}
DAO
.
prototype
.
toJSON
=
function
()
{
return
this
.
dataValues
;
return
this
.
get
()
;
}
// private
...
...
@@ -651,6 +655,12 @@ module.exports = (function() {
}
}
Utils
.
_
.
each
(
this
.
attributes
,
function
(
key
)
{
if
(
!
values
.
hasOwnProperty
(
key
))
{
values
[
key
]
=
undefined
}
})
this
.
set
(
values
,
options
)
}
...
...
test/dao-factory/create.test.js
View file @
6367758
...
...
@@ -700,7 +700,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'properly handles disparate field lists'
,
function
(
done
)
{
it
.
only
(
'properly handles disparate field lists'
,
function
(
done
)
{
var
self
=
this
,
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
},
{
username
:
'Paul'
},
...
...
@@ -713,6 +713,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect
(
users
[
0
].
secretValue
).
to
.
be
.
null
done
()
})
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
})
...
...
test/include.test.js
View file @
6367758
...
...
@@ -365,9 +365,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
ranks
:
function
(
callback
)
{
Rank
.
bulkCreate
([
{
name
:
'Admin'
,
canInvite
:
1
,
canRemove
:
1
},
{
name
:
'Member'
,
canInvite
:
1
}
{
name
:
'Member'
,
canInvite
:
1
,
canRemove
:
0
}
]).
done
(
function
()
{
Rank
.
findAll
().
done
(
callback
)
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
},
memberships
:
[
'user'
,
'groups'
,
'ranks'
,
function
(
callback
,
results
)
{
...
...
@@ -545,7 +547,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
ranks
:
function
(
callback
)
{
Rank
.
bulkCreate
([
{
name
:
'Admin'
,
canInvite
:
1
,
canRemove
:
1
},
{
name
:
'Member'
,
canInvite
:
1
}
{
name
:
'Member'
,
canInvite
:
1
,
canRemove
:
0
}
]).
done
(
function
()
{
Rank
.
findAll
().
done
(
callback
)
})
...
...
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