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 a335f846
authored
Jul 30, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
You can now use .find() on any single integer primary key when throwing just a n…
…umber as an argument.
1 parent
9a41b4ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
8 deletions
lib/dao-factory.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
a335f84
...
@@ -250,14 +250,21 @@ module.exports = (function() {
...
@@ -250,14 +250,21 @@ module.exports = (function() {
}
}
var
primaryKeys
=
this
.
primaryKeys
var
primaryKeys
=
this
.
primaryKeys
,
keys
=
Object
.
keys
(
primaryKeys
)
,
keysLength
=
keys
.
length
// options is not a hash but an id
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
if
(
typeof
options
===
'number'
)
{
options
=
{
where
:
options
}
var
oldOption
=
options
options
=
{
where
:
{}
}
if
(
keysLength
===
1
)
{
options
.
where
[
keys
[
0
]]
=
oldOption
}
else
{
options
.
where
.
id
=
oldOption
}
}
else
if
(
Utils
.
_
.
size
(
primaryKeys
)
&&
Utils
.
argsArePrimaryKeys
(
arguments
,
primaryKeys
))
{
}
else
if
(
Utils
.
_
.
size
(
primaryKeys
)
&&
Utils
.
argsArePrimaryKeys
(
arguments
,
primaryKeys
))
{
var
where
=
{}
var
where
=
{}
,
self
=
this
,
self
=
this
,
keys
=
Object
.
keys
(
primaryKeys
)
Utils
.
_
.
each
(
arguments
,
function
(
arg
,
i
)
{
Utils
.
_
.
each
(
arguments
,
function
(
arg
,
i
)
{
var
key
=
keys
[
i
]
var
key
=
keys
[
i
]
...
...
test/dao-factory.test.js
View file @
a335f84
...
@@ -1330,17 +1330,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1330,17 +1330,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{
where
:
{
id
:
0
}},
{
where
:
{
id
:
0
}},
{
where
:
{
id
:
'0'
}}
{
where
:
{
id
:
'0'
}}
]
]
,
done
=
_
.
after
(
2
*
permutations
.
length
,
_done
)
;
,
done
=
_
.
after
(
2
*
permutations
.
length
,
_done
)
this
.
User
.
bulkCreate
([{
username
:
'jack'
},
{
username
:
'jack'
}]).
success
(
function
()
{
this
.
User
.
bulkCreate
([{
username
:
'jack'
},
{
username
:
'jack'
}]).
success
(
function
()
{
permutations
.
forEach
(
function
(
perm
)
{
permutations
.
forEach
(
function
(
perm
)
{
self
.
User
.
find
(
perm
).
done
(
function
(
err
,
user
)
{
self
.
User
.
find
(
perm
).
done
(
function
(
err
,
user
)
{
expect
(
err
).
to
.
be
.
null
;
expect
(
err
).
to
.
be
.
null
expect
(
user
).
to
.
be
.
null
;
expect
(
user
).
to
.
be
.
null
done
()
;
done
()
}).
on
(
'sql'
,
function
(
s
)
{
}).
on
(
'sql'
,
function
(
s
)
{
expect
(
s
.
indexOf
(
0
)).
not
.
to
.
equal
(
-
1
);
expect
(
s
.
indexOf
(
0
)).
not
.
to
.
equal
(
-
1
)
done
();
done
()
})
})
})
})
it
(
'should allow us to find IDs using capital letters'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
ID
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
Login
:
{
type
:
Sequelize
.
STRING
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
Login
:
'foo'
}).
success
(
function
()
{
User
.
find
(
1
).
success
(
function
(
user
)
{
expect
(
user
).
to
.
exist
expect
(
user
.
ID
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
...
@@ -2053,6 +2070,23 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -2053,6 +2070,23 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
})
})
it
(
'should allow us to find IDs using capital letters'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
ID
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
Login
:
{
type
:
Sequelize
.
STRING
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
Login
:
'foo'
}).
success
(
function
()
{
User
.
findAll
({
ID
:
1
}).
success
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
instanceof
(
Array
)
expect
(
user
).
to
.
have
.
length
(
1
)
done
()
})
})
})
})
})
})
})
})
...
...
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