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 defcb043
authored
Jun 22, 2012
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cherry picking done
1 parent
c76d575d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
19 deletions
lib/associations/has-one.js
lib/sequelize.js
lib/utils.js
spec-jasmine/dao.spec.js
lib/associations/has-one.js
View file @
defcb04
...
@@ -23,12 +23,21 @@ module.exports = (function() {
...
@@ -23,12 +23,21 @@ module.exports = (function() {
// the id is in the target table
// the id is in the target table
HasOne
.
prototype
.
injectAttributes
=
function
()
{
HasOne
.
prototype
.
injectAttributes
=
function
()
{
var
newAttributes
=
{}
var
newAttributes
=
{},
self
=
this
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableName
)
+
"Id"
,
this
.
options
.
underscored
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableName
)
+
"Id"
,
this
.
options
.
underscored
)
newAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
}
if
(
Utils
.
isHash
(
this
.
identifier
))
{
Utils
.
_
.
each
(
this
.
identifier
,
function
(
elem
,
key
)
{
newAttributes
[
key
]
=
self
.
identifier
[
key
].
type
||
DataTypes
.
INTEGER
})
}
else
{
newAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
}
}
Utils
.
_
.
extend
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
extend
(
this
.
target
.
rawAttributes
,
newAttributes
)
return
this
return
this
}
}
...
@@ -37,9 +46,8 @@ module.exports = (function() {
...
@@ -37,9 +46,8 @@ module.exports = (function() {
obj
[
this
.
accessors
.
get
]
=
function
()
{
obj
[
this
.
accessors
.
get
]
=
function
()
{
var
id
=
obj
.
id
var
id
=
obj
.
id
,
where
=
{}
,
where
=
Utils
.
setAttributes
({},
self
.
identifier
,
obj
)
where
[
self
.
identifier
]
=
id
return
self
.
target
.
find
({
where
:
where
})
return
self
.
target
.
find
({
where
:
where
})
}
}
...
@@ -53,16 +61,11 @@ module.exports = (function() {
...
@@ -53,16 +61,11 @@ module.exports = (function() {
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
obj
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
obj
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
if
(
oldObj
)
{
if
(
oldObj
)
{
<<<<<<<
HEAD
oldObj
=
Utils
.
setAttributes
(
oldObj
,
self
.
identifier
,
self
.
options
.
omitNull
?
''
:
null
)
oldObj
[
self
.
identifier
]
=
null
=======
console
.
log
(
self
.
options
);
oldObj
=
Utils
.
setAttributes
(
oldObj
,
self
.
identifier
,
null
)
>>>>>>>
03
b8bfa
...
option
renamed
to
omitNull
.
Ignores
both
null
and
undefined
.
Tested
and
working
for
postgres
and
sqlite
oldObj
.
save
()
oldObj
.
save
()
}
}
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
=
Utils
.
setAttributes
(
associatedObject
,
self
.
identifier
,
obj
)
associatedObject
.
save
()
associatedObject
.
save
()
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
...
@@ -75,4 +78,4 @@ module.exports = (function() {
...
@@ -75,4 +78,4 @@ module.exports = (function() {
}
}
return
HasOne
return
HasOne
})()
})()
\ No newline at end of file
lib/sequelize.js
View file @
defcb04
...
@@ -19,7 +19,8 @@ module.exports = (function() {
...
@@ -19,7 +19,8 @@ module.exports = (function() {
define
:
{},
define
:
{},
query
:
{},
query
:
{},
sync
:
{},
sync
:
{},
logging
:
console
.
log
logging
:
console
.
log
,
omitNull
:
false
},
options
||
{})
},
options
||
{})
if
(
this
.
options
.
logging
===
true
)
{
if
(
this
.
options
.
logging
===
true
)
{
...
@@ -47,7 +48,7 @@ module.exports = (function() {
...
@@ -47,7 +48,7 @@ module.exports = (function() {
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
prototype
.
getQueryInterface
=
function
()
{
Sequelize
.
prototype
.
getQueryInterface
=
function
()
{
this
.
queryInterface
=
this
.
queryInterface
||
new
QueryInterface
(
this
)
this
.
queryInterface
=
this
.
queryInterface
||
new
QueryInterface
(
this
)
return
this
.
queryInterface
return
this
.
queryInterface
}
}
...
@@ -65,6 +66,7 @@ module.exports = (function() {
...
@@ -65,6 +66,7 @@ module.exports = (function() {
if
(
this
.
options
.
define
)
if
(
this
.
options
.
define
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
define
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
define
)
options
.
omitNull
=
this
.
options
.
omitNull
var
factory
=
new
DAOFactory
(
daoName
,
attributes
,
options
)
var
factory
=
new
DAOFactory
(
daoName
,
attributes
,
options
)
...
@@ -127,4 +129,4 @@ module.exports = (function() {
...
@@ -127,4 +129,4 @@ module.exports = (function() {
}
}
return
Sequelize
return
Sequelize
})()
})()
\ No newline at end of file
lib/utils.js
View file @
defcb04
...
@@ -97,9 +97,22 @@ var Utils = module.exports = {
...
@@ -97,9 +97,22 @@ var Utils = module.exports = {
toDefaultValue
:
function
(
value
)
{
toDefaultValue
:
function
(
value
)
{
return
(
value
==
DataTypes
.
NOW
)
?
new
Date
()
:
value
return
(
value
==
DataTypes
.
NOW
)
?
new
Date
()
:
value
},
setAttributes
:
function
(
hash
,
identifier
,
instance
,
prefix
)
{
prefix
=
prefix
||
''
if
(
this
.
isHash
(
identifier
))
{
this
.
_
.
each
(
identifier
,
function
(
elem
,
key
)
{
hash
[
prefix
+
key
]
=
Utils
.
_
.
isString
(
instance
)
?
instance
:
Utils
.
_
.
isObject
(
instance
)
?
instance
[
elem
.
key
||
elem
]
:
null
})
}
else
{
hash
[
prefix
+
identifier
]
=
Utils
.
_
.
isString
(
instance
)
?
instance
:
Utils
.
_
.
isObject
(
instance
)
?
instance
.
id
:
null
}
return
hash
}
}
}
}
Utils
.
CustomEventEmitter
=
require
(
"./emitters/custom-event-emitter"
)
Utils
.
CustomEventEmitter
=
require
(
"./emitters/custom-event-emitter"
)
Utils
.
QueryChainer
=
require
(
"./query-chainer"
)
Utils
.
QueryChainer
=
require
(
"./query-chainer"
)
Utils
.
Lingo
=
require
(
"lingo"
)
Utils
.
Lingo
=
require
(
"lingo"
)
\ No newline at end of file
spec-jasmine/dao.spec.js
View file @
defcb04
...
@@ -575,7 +575,7 @@ describe('DAO', function() {
...
@@ -575,7 +575,7 @@ describe('DAO', function() {
it
(
'returns a response that can be stringified'
,
function
()
{
it
(
'returns a response that can be stringified'
,
function
()
{
var
self
=
this
var
self
=
this
var
User
=
sequelize
.
define
(
'User'
,
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
,
age
:
Sequelize
.
INTEGER
,
isAdmin
:
Sequelize
.
BOOLEAN
username
:
Sequelize
.
STRING
,
age
:
Sequelize
.
INTEGER
,
isAdmin
:
Sequelize
.
BOOLEAN
},
{
timestamps
:
false
,
logging
:
false
})
},
{
timestamps
:
false
,
logging
:
false
})
...
...
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