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 ff96051e
authored
Jan 03, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use custom getters in get()
1 parent
5228c35b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
lib/dao.js
test/dao/values.test.js
lib/dao.js
View file @
ff96051
...
@@ -100,6 +100,17 @@ module.exports = (function() {
...
@@ -100,6 +100,17 @@ module.exports = (function() {
return
this
.
dataValues
[
key
]
return
this
.
dataValues
[
key
]
}
}
if
(
this
.
_hasCustomGetters
)
{
var
values
=
{}
,
key
for
(
key
in
this
.
dataValues
)
{
if
(
this
.
dataValues
.
hasOwnProperty
(
key
))
{
values
[
key
]
=
this
.
get
(
key
)
}
}
return
values
}
return
this
.
dataValues
return
this
.
dataValues
}
}
DAO
.
prototype
.
set
=
function
(
key
,
value
,
options
)
{
DAO
.
prototype
.
set
=
function
(
key
,
value
,
options
)
{
...
...
test/dao/values.test.js
View file @
ff96051
...
@@ -137,7 +137,37 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -137,7 +137,37 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
describe
(
'get'
,
function
()
{
describe
(
'get'
,
function
()
{
it
(
'should use custom getters in get(key)'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
price
:
{
type
:
Sequelize
.
STRING
,
get
:
function
()
{
return
this
.
dataValues
[
'price'
]
*
100
}
}
})
var
product
=
Product
.
build
({
price
:
10
})
expect
(
product
.
get
(
'price'
)).
to
.
equal
(
1000
)
})
it
(
'should use custom getters in toJSON'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
price
:
{
type
:
Sequelize
.
STRING
,
get
:
function
()
{
return
this
.
dataValues
[
'price'
]
*
100
}
}
})
var
product
=
Product
.
build
({
price
:
10
})
expect
(
product
.
toJSON
()).
to
.
deep
.
equal
({
price
:
1000
,
id
:
null
})
})
})
})
describe
(
'changed'
,
function
()
{
describe
(
'changed'
,
function
()
{
...
...
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