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 71db9197
authored
Feb 18, 2015
by
Jumpei Ogawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clearify how to use Getters & Setters
1 parent
478363ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
docs/docs/models.md
docs/docs/models.md
View file @
71db919
...
@@ -134,22 +134,30 @@ Getters and Setters can be defined in 2 ways (you can mix and match these 2
...
@@ -134,22 +134,30 @@ Getters and Setters can be defined in 2 ways (you can mix and match these 2
### Defining as part of a property
### Defining as part of a property
```
js
```
js
var
Foo
=
sequelize
.
define
(
'Foo'
,
{
var
Employee
=
sequelize
.
define
(
'Employee'
,
{
name
:
Sequelize
.
STRING
,
name
:
{
title
:
{
type
:
Sequelize
.
STRING
,
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
allowNull
:
false
,
get
:
function
()
{
get
:
function
()
{
/*
var
title
=
this
.
getDataValue
(
'title'
);
// 'this' allows you to access attributes of the instance
do your magic here and return something!
return
this
.
getDataValue
(
'name'
)
+
' ('
+
title
+
')'
;
'this' allows you to access attributes of the model.
example: this.getDataValue('name') works
*/
},
},
set
:
function
(
v
)
{
/* do your magic with the input here! */
}
},
title
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
set
:
function
(
val
)
{
this
.
setDataValue
(
'title'
,
val
.
toUpperCase
());
}
}
}
});
});
Employee
.
create
({
name
:
'John Doe'
,
title
:
'senior engineer'
})
.
then
(
function
(
employee
)
{
console
.
log
(
employee
.
get
(
'name'
));
// John Doe (SENIOR ENGINEER)
console
.
log
(
employee
.
get
(
'title'
));
// SENIOR ENGINEER
})
```
```
### Defining as part of the model options
### Defining as part of the model options
...
...
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