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 45fce2bf
authored
Nov 13, 2012
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assocations
1 parent
c77c2bc3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
16 deletions
lib/associations/belongs-to.js
lib/associations/has-one.js
lib/dao-factory.js
lib/dao.js
lib/associations/belongs-to.js
View file @
45fce2b
...
...
@@ -33,7 +33,7 @@ module.exports = (function() {
,
accessor
=
Utils
.
_
.
camelize
(
'get_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
)))
obj
[
accessor
]
=
function
()
{
var
id
=
obj
[
self
.
identifier
]
var
id
=
this
[
self
.
identifier
]
return
self
.
target
.
find
(
id
)
}
...
...
@@ -45,10 +45,10 @@ module.exports = (function() {
,
accessor
=
Utils
.
_
.
camelize
(
'set_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
)))
obj
[
accessor
]
=
function
(
associatedObject
)
{
obj
[
self
.
identifier
]
=
associatedObject
?
associatedObject
.
id
:
null
this
[
self
.
identifier
]
=
associatedObject
?
associatedObject
.
id
:
null
// passes the changed field to save, so only that field get updated.
return
obj
.
save
([
self
.
identifier
])
return
this
.
save
([
self
.
identifier
])
}
return
this
...
...
lib/associations/has-one.js
View file @
45fce2b
...
...
@@ -53,15 +53,16 @@ module.exports = (function() {
,
options
=
self
.
options
||
{}
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
)
{
var
instance
=
this
;
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
obj
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
instance
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
if
(
oldObj
)
{
oldObj
[
self
.
identifier
]
=
null
oldObj
.
save
()
}
if
(
associatedObject
)
{
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
[
self
.
identifier
]
=
instance
.
id
associatedObject
.
save
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
associatedObject
)
})
...
...
lib/dao-factory.js
View file @
45fce2b
...
...
@@ -27,11 +27,8 @@ module.exports = (function() {
// extract validation
this
.
validate
=
this
.
options
.
validate
||
{}
// DAO prototype
this
.
DAO
=
function
(
values
,
options
)
{
this
.
DAO
=
function
()
{
DAO
.
apply
(
this
,
arguments
);
};
Util
.
inherits
(
this
.
DAO
,
DAO
);
...
...
@@ -229,10 +226,6 @@ module.exports = (function() {
})
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
||
{},
function
(
fct
,
name
)
{
instance
[
name
]
=
fct
})
// Utils._.each(this.associations, function(association) {
// association.injectGetter(instance)
// association.injectSetter(instance)
// })
instance
.
isNewRecord
=
options
.
hasOwnProperty
(
'isNewRecord'
)
?
options
.
isNewRecord
:
true
instance
.
selectedValues
=
values
...
...
lib/dao.js
View file @
45fce2b
...
...
@@ -285,8 +285,5 @@ module.exports = (function() {
}
}
/* Add the instance methods to DAO */
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
return
DAO
})()
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