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 a814e7fa
authored
Mar 07, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made it possible to override instance and class methods. Closes #1359
1 parent
a1c2f6a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
lib/sequelize.js
test/sequelize.test.js
lib/sequelize.js
View file @
a814e7f
...
@@ -214,7 +214,7 @@ module.exports = (function() {
...
@@ -214,7 +214,7 @@ module.exports = (function() {
Utils
.
_
([
'classMethods'
,
'instanceMethods'
]).
each
(
function
(
key
)
{
Utils
.
_
([
'classMethods'
,
'instanceMethods'
]).
each
(
function
(
key
)
{
if
(
globalOptions
.
define
[
key
])
{
if
(
globalOptions
.
define
[
key
])
{
options
[
key
]
=
options
[
key
]
||
{}
options
[
key
]
=
options
[
key
]
||
{}
Utils
.
_
.
extend
(
options
[
key
],
globalOptions
.
define
[
key
])
Utils
.
_
.
defaults
(
options
[
key
],
globalOptions
.
define
[
key
])
}
}
})
})
}
}
...
...
test/sequelize.test.js
View file @
a814e7f
...
@@ -408,21 +408,57 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -408,21 +408,57 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
done
()
done
()
})
})
it
(
"inherits global classMethods and instanceMethods"
,
function
(
done
)
{
it
(
"inherits global classMethods and instanceMethods, and can override global methods with local ones"
,
function
(
done
)
{
var
sequelize
=
Support
.
createSequelizeInstance
({
var
globalClassMethod
=
sinon
.
spy
()
define
:
{
,
globalInstanceMethod
=
sinon
.
spy
()
classMethods
:
{
globalClassMethod
:
function
()
{}
},
,
localClassMethod
=
sinon
.
spy
()
instanceMethods
:
{
globalInstanceMethod
:
function
()
{}
}
,
localInstanceMethod
=
sinon
.
spy
()
}
,
sequelize
=
Support
.
createSequelizeInstance
({
})
define
:
{
classMethods
:
{
globalClassMethod
:
function
()
{},
overrideMe
:
globalClassMethod
},
instanceMethods
:
{
globalInstanceMethod
:
function
()
{},
overrideMe
:
globalInstanceMethod
}
}
})
,
DAO
var
DAO
=
sequelize
.
define
(
'foo'
,
{
bar
:
DataTypes
.
STRING
},
{
DAO
=
sequelize
.
define
(
'foo'
,
{
bar
:
DataTypes
.
STRING
},
{
classMethods
:
{
localClassMethod
:
function
()
{}
}
classMethods
:
{
localClassMethod
:
function
()
{}
}
})
})
expect
(
typeof
DAO
.
options
.
classMethods
.
globalClassMethod
).
to
.
equal
(
'function'
)
expect
(
typeof
DAO
.
options
.
classMethods
.
globalClassMethod
).
to
.
equal
(
'function'
)
expect
(
typeof
DAO
.
options
.
classMethods
.
localClassMethod
).
to
.
equal
(
'function'
)
expect
(
typeof
DAO
.
options
.
classMethods
.
localClassMethod
).
to
.
equal
(
'function'
)
expect
(
typeof
DAO
.
options
.
instanceMethods
.
globalInstanceMethod
).
to
.
equal
(
'function'
)
expect
(
typeof
DAO
.
options
.
instanceMethods
.
globalInstanceMethod
).
to
.
equal
(
'function'
)
// This DAO inherits the global methods
DAO
.
overrideMe
()
DAO
.
build
().
overrideMe
()
DAO
=
sequelize
.
define
(
'foo'
,
{
bar
:
DataTypes
.
STRING
},
{
classMethods
:
{
overrideMe
:
localClassMethod
},
instanceMethods
:
{
overrideMe
:
localInstanceMethod
}
})
// This DAO has its own implementation
DAO
.
overrideMe
()
DAO
.
build
().
overrideMe
()
expect
(
globalClassMethod
).
to
.
have
.
been
.
calledOnce
expect
(
globalInstanceMethod
).
to
.
have
.
been
.
calledOnce
expect
(
localClassMethod
).
to
.
have
.
been
.
calledOnce
expect
(
localInstanceMethod
).
to
.
have
.
been
.
calledOnce
done
()
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