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 ee908129
authored
Jan 05, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored __defineGetter__ to Object.defineProperty
1 parent
8a0b2d5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
45 deletions
lib/model.js
lib/model.js
View file @
ee90812
...
@@ -7,9 +7,9 @@ module.exports = (function() {
...
@@ -7,9 +7,9 @@ module.exports = (function() {
var
Model
=
function
(
values
,
options
)
{
var
Model
=
function
(
values
,
options
)
{
var
self
=
this
var
self
=
this
this
.
__factory
=
null
// will be set in Model.build
this
.
attributes
=
[]
this
.
attributes
=
[]
this
.
validators
=
{}
// holds validation settings for each attribute
this
.
validators
=
{}
// holds validation settings for each attribute
this
.
__factory
=
null
// will be set in Model.build
this
.
__options
=
Utils
.
_
.
extend
({
this
.
__options
=
Utils
.
_
.
extend
({
underscored
:
false
,
underscored
:
false
,
hasPrimaryKeys
:
false
,
hasPrimaryKeys
:
false
,
...
@@ -33,6 +33,58 @@ module.exports = (function() {
...
@@ -33,6 +33,58 @@ module.exports = (function() {
get
:
function
(){
return
this
.
QueryInterface
.
QueryGenerator
}
get
:
function
(){
return
this
.
QueryInterface
.
QueryGenerator
}
})
})
Object
.
defineProperty
(
Model
.
prototype
,
'isDeleted'
,
{
get
:
function
()
{
var
result
=
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
result
=
result
&&
this
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
!=
null
return
result
}
})
Object
.
defineProperty
(
Model
.
prototype
,
'values'
,
{
get
:
function
()
{
var
result
=
{}
,
self
=
this
this
.
attributes
.
forEach
(
function
(
attr
)
{
result
[
attr
]
=
self
[
attr
]
})
return
result
}
})
Object
.
defineProperty
(
Model
.
prototype
,
'primaryKeyValues'
,
{
get
:
function
()
{
var
result
=
{}
,
self
=
this
Utils
.
_
.
each
(
this
.
__factory
.
primaryKeys
,
function
(
_
,
attr
)
{
result
[
attr
]
=
self
[
attr
]
})
return
result
}
})
Object
.
defineProperty
(
Model
.
prototype
,
"identifiers"
,
{
get
:
function
()
{
var
primaryKeys
=
Utils
.
_
.
keys
(
this
.
__factory
.
primaryKeys
)
,
result
=
{}
,
self
=
this
if
(
!
this
.
__factory
.
hasPrimaryKeys
)
primaryKeys
=
[
'id'
]
primaryKeys
.
forEach
(
function
(
identifier
)
{
result
[
identifier
]
=
self
[
identifier
]
})
return
result
}
})
Model
.
prototype
.
save
=
function
()
{
Model
.
prototype
.
save
=
function
()
{
var
updatedAtAttr
=
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
var
updatedAtAttr
=
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
...
@@ -147,50 +199,6 @@ module.exports = (function() {
...
@@ -147,50 +199,6 @@ module.exports = (function() {
}
}
}
}
Model
.
prototype
.
__defineGetter__
(
"identifiers"
,
function
()
{
var
primaryKeys
=
Utils
.
_
.
keys
(
this
.
__factory
.
primaryKeys
)
,
result
=
{}
,
self
=
this
if
(
!
this
.
__factory
.
hasPrimaryKeys
)
primaryKeys
=
[
'id'
]
primaryKeys
.
forEach
(
function
(
identifier
)
{
result
[
identifier
]
=
self
[
identifier
]
})
return
result
})
Model
.
prototype
.
__defineGetter__
(
'isDeleted'
,
function
()
{
var
result
=
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
result
=
result
&&
this
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
!=
null
return
result
})
Model
.
prototype
.
__defineGetter__
(
'values'
,
function
()
{
var
result
=
{}
,
self
=
this
this
.
attributes
.
forEach
(
function
(
attr
)
{
result
[
attr
]
=
self
[
attr
]
})
return
result
})
Model
.
prototype
.
__defineGetter__
(
'primaryKeyValues'
,
function
()
{
var
result
=
{}
,
self
=
this
Utils
.
_
.
each
(
this
.
__factory
.
primaryKeys
,
function
(
_
,
attr
)
{
result
[
attr
]
=
self
[
attr
]
})
return
result
})
Model
.
prototype
.
equals
=
function
(
other
)
{
Model
.
prototype
.
equals
=
function
(
other
)
{
var
result
=
true
var
result
=
true
,
self
=
this
,
self
=
this
...
...
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