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 1937368f
authored
Aug 30, 2013
by
Joe Wilm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Sequelize#model to fetch DAOFactory of previously defined model
1 parent
96874904
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
lib/sequelize.js
test/sequelize.test.js
lib/sequelize.js
View file @
1937368
...
@@ -195,6 +195,20 @@ module.exports = (function() {
...
@@ -195,6 +195,20 @@ module.exports = (function() {
return
factory
return
factory
}
}
/**
Fetch a DAO factory
@param {String} daoName The name of a model defined with Sequelize.define
@returns {DAOFactory} The DAOFactory for daoName
*/
Sequelize
.
prototype
.
model
=
function
(
daoName
)
{
if
(
!
this
.
isDefined
(
daoName
))
{
throw
new
Error
(
daoName
+
' has not been defined'
)
}
return
this
.
daoFactoryManager
.
getDAO
(
daoName
)
}
Sequelize
.
prototype
.
isDefined
=
function
(
daoName
)
{
Sequelize
.
prototype
.
isDefined
=
function
(
daoName
)
{
var
daos
=
this
.
daoFactoryManager
.
daos
var
daos
=
this
.
daoFactoryManager
.
daos
return
(
daos
.
filter
(
function
(
dao
)
{
return
dao
.
name
===
daoName
}).
length
!==
0
)
return
(
daos
.
filter
(
function
(
dao
)
{
return
dao
.
name
===
daoName
}).
length
!==
0
)
...
...
test/sequelize.test.js
View file @
1937368
...
@@ -51,6 +51,23 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -51,6 +51,23 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
})
})
})
describe
(
'model'
,
function
()
{
it
(
'throws an error if the dao being accessed is undefined'
,
function
()
{
var
self
=
this
expect
(
function
()
{
self
.
sequelize
.
model
(
'Project'
)
}).
to
.
throw
(
/project has not been defined/i
)
})
it
(
'returns the dao factory defined by daoName'
,
function
()
{
var
project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
DataTypes
.
STRING
})
expect
(
this
.
sequelize
.
model
(
'Project'
)).
to
.
equal
(
project
)
})
})
describe
(
'query'
,
function
()
{
describe
(
'query'
,
function
()
{
afterEach
(
function
(
done
)
{
afterEach
(
function
(
done
)
{
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
...
...
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