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 0ca7c044
authored
Mar 29, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
functions without parameters are getters now
1 parent
cabfdfee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
23 deletions
lib/sequelize/model-definition.js
lib/sequelize/model.js
lib/sequelize/model-definition.js
View file @
0ca7c04
...
...
@@ -27,16 +27,16 @@ ModelDefinition.prototype.sync = function(options) {
.
on
(
'failure'
,
function
()
{
self
.
emit
(
'failure'
)
})
}
if
(
options
.
force
)
this
.
drop
()
.
on
(
'success'
,
function
()
{
doQuery
()
})
if
(
options
.
force
)
this
.
drop
.
on
(
'success'
,
function
()
{
doQuery
()
})
else
doQuery
()
return
this
}
ModelDefinition
.
prototype
.
drop
=
function
()
{
ModelDefinition
.
prototype
.
__defineGetter__
(
'drop'
,
function
()
{
var
query
=
QueryGenerator
.
dropTableQuery
(
this
.
tableName
)
return
this
.
modelManager
.
sequelize
.
query
(
query
)
}
}
)
ModelDefinition
.
prototype
.
build
=
function
(
values
)
{
var
instance
=
new
Model
(
values
)
...
...
@@ -48,5 +48,5 @@ ModelDefinition.prototype.build = function(values) {
}
ModelDefinition
.
prototype
.
create
=
function
(
values
)
{
return
this
.
build
(
values
).
save
()
return
this
.
build
(
values
).
save
}
\ No newline at end of file
lib/sequelize/model.js
View file @
0ca7c04
...
...
@@ -9,6 +9,7 @@ var Model = module.exports = function(values) {
this
.
attributes
=
[]
this
.
addAttribute
(
'id'
,
null
)
// a newly created model has no id
// add all passed values to the model and store the attribute names in this.attributes
Utils
.
_
.
map
(
values
,
function
(
value
,
key
)
{
self
.
addAttribute
(
key
,
value
)
})
}
Utils
.
addEventEmitter
(
Model
)
...
...
@@ -20,29 +21,30 @@ Model.Events = {
destroy
:
'DestroyQuery'
}
var
instanceMethods
=
{
save
:
function
()
{
if
(
this
.
isNewRecord
)
{
var
query
=
QueryGenerator
.
insertQuery
(
this
.
definition
.
tableName
,
this
.
values
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
)
}
else
{
var
query
=
QueryGenerate
.
updateQuery
(
this
.
definition
.
tableName
,
this
.
values
,
this
.
id
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
)
}
},
destroy
:
function
()
{
var
query
=
QueryGenerate
.
deleteQuery
(
this
.
definition
.
tableName
,
this
.
id
)
Model
.
prototype
.
addAttribute
=
function
(
attribute
,
value
)
{
this
[
attribute
]
=
value
this
.
attributes
.
push
(
attribute
)
}
Model
.
prototype
.
__defineGetter__
(
'save'
,
function
()
{
if
(
this
.
isNewRecord
)
{
var
query
=
QueryGenerator
.
insertQuery
(
this
.
definition
.
tableName
,
this
.
values
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
)
}
else
{
var
query
=
QueryGenerate
.
updateQuery
(
this
.
definition
.
tableName
,
this
.
values
,
this
.
id
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
)
},
addAttribute
:
function
(
attribute
,
value
)
{
this
[
attribute
]
=
value
this
.
attributes
.
push
(
attribute
)
}
}
})
Model
.
prototype
.
__defineGetter__
(
'destroy'
,
function
()
{
var
query
=
QueryGenerate
.
deleteQuery
(
this
.
definition
.
tableName
,
this
.
id
)
return
this
.
definition
.
modelManager
.
sequelize
.
query
(
query
)
})
Model
.
prototype
.
__defineGetter__
(
'isNewRecord'
,
function
()
{
return
this
.
id
==
null
})
Model
.
prototype
.
__defineGetter__
(
'values'
,
function
()
{
var
result
=
{}
,
self
=
this
...
...
@@ -55,5 +57,4 @@ Model.prototype.__defineGetter__('values', function() {
})
/* Add the instance methods to Model */
Utils
.
_
.
map
(
instanceMethods
,
function
(
fct
,
name
)
{
Model
.
prototype
[
name
]
=
fct
})
Utils
.
_
.
map
(
Mixin
.
instanceMethods
,
function
(
fct
,
name
)
{
Model
.
prototype
[
name
]
=
fct
})
\ No newline at end of file
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