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 5a1631ee
authored
Jan 15, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fracture' of
git://github.com/durango/sequelize
into durango-fracture
2 parents
322e1bb0
01abe949
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
lib/dao-factory.js
lib/dao.js
spec/dao.spec.js
lib/dao-factory.js
View file @
5a1631e
...
@@ -15,7 +15,8 @@ module.exports = (function() {
...
@@ -15,7 +15,8 @@ module.exports = (function() {
freezeTableName
:
false
,
freezeTableName
:
false
,
underscored
:
false
,
underscored
:
false
,
syncOnAssociation
:
true
,
syncOnAssociation
:
true
,
paranoid
:
false
paranoid
:
false
,
whereCollection
:
null
},
options
||
{})
},
options
||
{})
this
.
name
=
name
this
.
name
=
name
...
@@ -54,7 +55,7 @@ module.exports = (function() {
...
@@ -54,7 +55,7 @@ module.exports = (function() {
this
.
primaryKeys
=
{};
this
.
primaryKeys
=
{};
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
// If you don't specify a valid data type lets help you debug it
// If you don't specify a valid data type lets help you debug it
if
(
dataTypeString
===
undefined
)
throw
new
Error
(
"Unrecognized data type for field "
+
attributeName
);
if
(
dataTypeString
===
undefined
)
throw
new
Error
(
"Unrecognized data type for field "
+
attributeName
);
if
((
attributeName
!=
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
))
{
if
((
attributeName
!=
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
))
{
self
.
primaryKeys
[
attributeName
]
=
dataTypeString
self
.
primaryKeys
[
attributeName
]
=
dataTypeString
}
}
...
@@ -150,7 +151,10 @@ module.exports = (function() {
...
@@ -150,7 +151,10 @@ module.exports = (function() {
if
(
!
options
.
include
[
daoName
])
{
if
(
!
options
.
include
[
daoName
])
{
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
}
}
}.
bind
(
this
))
}.
bind
(
this
));
// whereCollection is used for non-primary key updates
this
.
options
.
whereCollection
=
options
.
where
||
null
;
}
}
return
this
.
QueryInterface
.
select
(
this
,
this
.
tableName
,
options
,
{
type
:
'SELECT'
,
hasJoin
:
hasJoin
})
return
this
.
QueryInterface
.
select
(
this
,
this
.
tableName
,
options
,
{
type
:
'SELECT'
,
hasJoin
:
hasJoin
})
...
@@ -161,6 +165,9 @@ module.exports = (function() {
...
@@ -161,6 +165,9 @@ module.exports = (function() {
var
optcpy
=
Utils
.
_
.
clone
(
options
)
var
optcpy
=
Utils
.
_
.
clone
(
options
)
optcpy
.
attributes
=
optcpy
.
attributes
||
[
Utils
.
addTicks
(
this
.
tableName
)
+
".*"
]
optcpy
.
attributes
=
optcpy
.
attributes
||
[
Utils
.
addTicks
(
this
.
tableName
)
+
".*"
]
// whereCollection is used for non-primary key updates
this
.
options
.
whereCollection
=
optcpy
.
where
||
null
;
return
this
.
QueryInterface
.
select
(
this
,
[
this
.
tableName
,
joinTableName
],
optcpy
,
{
type
:
'SELECT'
})
return
this
.
QueryInterface
.
select
(
this
,
[
this
.
tableName
,
joinTableName
],
optcpy
,
{
type
:
'SELECT'
})
}
}
...
@@ -210,7 +217,10 @@ module.exports = (function() {
...
@@ -210,7 +217,10 @@ module.exports = (function() {
if
(
!
options
.
include
[
daoName
])
{
if
(
!
options
.
include
[
daoName
])
{
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
}
}
}.
bind
(
this
))
}.
bind
(
this
));
// whereCollection is used for non-primary key updates
this
.
options
.
whereCollection
=
options
.
where
||
null
;
}
}
options
.
limit
=
1
options
.
limit
=
1
...
...
lib/dao.js
View file @
5a1631e
...
@@ -121,8 +121,12 @@ module.exports = (function() {
...
@@ -121,8 +121,12 @@ module.exports = (function() {
if
(
this
.
isNewRecord
)
{
if
(
this
.
isNewRecord
)
{
return
this
.
QueryInterface
.
insert
(
this
,
this
.
__factory
.
tableName
,
values
)
return
this
.
QueryInterface
.
insert
(
this
,
this
.
__factory
.
tableName
,
values
)
}
else
{
}
else
{
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
;
,
tableName
=
this
.
__factory
.
tableName
if
(
identifier
===
null
&&
this
.
__options
.
whereCollection
!==
null
)
identifier
=
this
.
__options
.
whereCollection
;
var
tableName
=
this
.
__factory
.
tableName
,
query
=
this
.
QueryInterface
.
update
(
this
,
tableName
,
values
,
identifier
)
,
query
=
this
.
QueryInterface
.
update
(
this
,
tableName
,
values
,
identifier
)
return
query
return
query
...
...
spec/dao.spec.js
View file @
5a1631e
...
@@ -19,9 +19,17 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
...
@@ -19,9 +19,17 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
})
})
self
.
HistoryLog
=
sequelize
.
define
(
'HistoryLog'
,
{
someText
:
{
type
:
DataTypes
.
STRING
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
},
aRandomId
:
{
type
:
DataTypes
.
INTEGER
}
})
},
},
onComplete
:
function
()
{
onComplete
:
function
()
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
self
.
User
.
sync
({
force
:
true
}).
success
(
function
(){
self
.
HistoryLog
.
sync
({
force
:
true
}).
success
(
done
)
})
}
}
})
})
})
})
...
@@ -67,6 +75,15 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
...
@@ -67,6 +75,15 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
done
()
done
()
})
})
})
})
it
(
'saves a record with no primary key'
,
function
(
done
){
this
.
HistoryLog
.
create
({
someText
:
'Some random text'
,
aNumber
:
3
,
aRandomId
:
5
}).
success
(
function
(
log
)
{
log
.
updateAttributes
({
aNumber
:
5
}).
success
(
function
(
newLog
){
expect
(
newLog
.
aNumber
).
toEqual
(
5
)
done
()
})
})
})
})
})
describe
(
'toJSON'
,
function
toJSON
()
{
describe
(
'toJSON'
,
function
toJSON
()
{
...
...
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