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 a57bd01d
authored
Jan 07, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed ModelManager to ModelFactoryManager
1 parent
8f84cc19
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
31 additions
and
28 deletions
changelog.md
lib/associations/has-many.js
lib/migrator.js
lib/model-manager.js → lib/model-factory-manager.js
lib/model-factory.js
lib/model.js
lib/sequelize.js
spec/associations/has-many.spec.js
spec/config/factories.js
spec/mysql/associations.spec.js
spec/sequelize.spec.js
changelog.md
View file @
a57bd01
# v1.3.1 #
-
[
REFACTORING
]
renamed ModelManager to ModelFactoryManager
# v1.3.0 #
# v1.3.0 #
-
[
REFACTORING
]
Model#all is now a function and not a getter.
-
[
REFACTORING
]
Model#all is now a function and not a getter.
-
[
REFACTORING
]
Renamed ModelDefinition to ModelFactory
-
[
REFACTORING
]
Renamed ModelDefinition to ModelFactory
...
...
lib/associations/has-many.js
View file @
a57bd01
...
@@ -48,7 +48,7 @@ module.exports = (function() {
...
@@ -48,7 +48,7 @@ module.exports = (function() {
combinedTableAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
foreignIdentifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
foreignIdentifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
this
.
connectorModel
=
this
.
source
.
modelManager
.
sequelize
.
define
(
this
.
combinedName
,
combinedTableAttributes
)
this
.
connectorModel
=
this
.
source
.
model
Factory
Manager
.
sequelize
.
define
(
this
.
combinedName
,
combinedTableAttributes
)
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorModel
=
this
.
connectorModel
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorModel
=
this
.
connectorModel
this
.
connectorModel
.
sync
()
this
.
connectorModel
.
sync
()
...
...
lib/migrator.js
View file @
a57bd01
...
@@ -119,7 +119,7 @@ module.exports = (function() {
...
@@ -119,7 +119,7 @@ module.exports = (function() {
var
self
=
this
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
storedModel
=
self
.
sequelize
.
modelManager
.
getModel
(
'SequelizeMeta'
)
var
storedModel
=
self
.
sequelize
.
model
Factory
Manager
.
getModel
(
'SequelizeMeta'
)
,
SequelizeMeta
=
storedModel
,
SequelizeMeta
=
storedModel
if
(
!
storedModel
)
{
if
(
!
storedModel
)
{
...
...
lib/model-manager.js
→
lib/model-
factory-
manager.js
View file @
a57bd01
module
.
exports
=
(
function
()
{
module
.
exports
=
(
function
()
{
var
ModelManager
=
function
(
sequelize
)
{
var
Model
Factory
Manager
=
function
(
sequelize
)
{
this
.
models
=
[]
this
.
models
=
[]
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
}
}
ModelManager
.
prototype
.
addModel
=
function
(
model
)
{
Model
Factory
Manager
.
prototype
.
addModel
=
function
(
model
)
{
this
.
models
.
push
(
model
)
this
.
models
.
push
(
model
)
return
model
return
model
}
}
ModelManager
.
prototype
.
removeModel
=
function
(
model
)
{
Model
Factory
Manager
.
prototype
.
removeModel
=
function
(
model
)
{
this
.
models
=
this
.
models
.
filter
(
function
(
_model
)
{
this
.
models
=
this
.
models
.
filter
(
function
(
_model
)
{
return
_model
.
name
!=
model
.
name
return
_model
.
name
!=
model
.
name
})
})
}
}
ModelManager
.
prototype
.
getModel
=
function
(
modelName
)
{
Model
Factory
Manager
.
prototype
.
getModel
=
function
(
modelName
)
{
var
model
=
this
.
models
.
filter
(
function
(
model
)
{
var
model
=
this
.
models
.
filter
(
function
(
model
)
{
return
model
.
name
==
modelName
return
model
.
name
==
modelName
})
})
...
@@ -24,9 +24,9 @@ module.exports = (function() {
...
@@ -24,9 +24,9 @@ module.exports = (function() {
return
!!
model
?
model
[
0
]
:
null
return
!!
model
?
model
[
0
]
:
null
}
}
ModelManager
.
prototype
.
__defineGetter__
(
'all'
,
function
()
{
Model
Factory
Manager
.
prototype
.
__defineGetter__
(
'all'
,
function
()
{
return
this
.
models
return
this
.
models
})
})
return
ModelManager
return
Model
Factory
Manager
})()
})()
lib/model-factory.js
View file @
a57bd01
...
@@ -19,7 +19,7 @@ module.exports = (function() {
...
@@ -19,7 +19,7 @@ module.exports = (function() {
this
.
name
=
name
this
.
name
=
name
this
.
tableName
=
this
.
options
.
freezeTableName
?
name
:
Utils
.
pluralize
(
name
)
this
.
tableName
=
this
.
options
.
freezeTableName
?
name
:
Utils
.
pluralize
(
name
)
this
.
rawAttributes
=
attributes
this
.
rawAttributes
=
attributes
this
.
modelManager
=
null
// defined in init function
this
.
model
Factory
Manager
=
null
// defined in init function
this
.
associations
=
{}
this
.
associations
=
{}
// extract validation
// extract validation
...
@@ -33,7 +33,7 @@ module.exports = (function() {
...
@@ -33,7 +33,7 @@ module.exports = (function() {
})
})
Object
.
defineProperty
(
ModelFactory
.
prototype
,
'QueryInterface'
,
{
Object
.
defineProperty
(
ModelFactory
.
prototype
,
'QueryInterface'
,
{
get
:
function
()
{
return
this
.
modelManager
.
sequelize
.
getQueryInterface
()
}
get
:
function
()
{
return
this
.
model
Factory
Manager
.
sequelize
.
getQueryInterface
()
}
})
})
Object
.
defineProperty
(
ModelFactory
.
prototype
,
'QueryGenerator'
,
{
Object
.
defineProperty
(
ModelFactory
.
prototype
,
'QueryGenerator'
,
{
...
@@ -48,8 +48,8 @@ module.exports = (function() {
...
@@ -48,8 +48,8 @@ module.exports = (function() {
get
:
function
()
{
return
this
.
primaryKeyCount
>
0
}
get
:
function
()
{
return
this
.
primaryKeyCount
>
0
}
})
})
ModelFactory
.
prototype
.
init
=
function
(
modelManager
)
{
ModelFactory
.
prototype
.
init
=
function
(
model
Factory
Manager
)
{
this
.
model
Manager
=
model
Manager
this
.
model
FactoryManager
=
modelFactory
Manager
addDefaultAttributes
.
call
(
this
)
addDefaultAttributes
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
...
@@ -189,7 +189,7 @@ module.exports = (function() {
...
@@ -189,7 +189,7 @@ module.exports = (function() {
var
query
=
function
()
{
var
query
=
function
()
{
var
args
=
Utils
.
_
.
map
(
arguments
,
function
(
arg
,
_
)
{
return
arg
})
var
args
=
Utils
.
_
.
map
(
arguments
,
function
(
arg
,
_
)
{
return
arg
})
,
s
=
this
.
modelManager
.
sequelize
,
s
=
this
.
model
Factory
Manager
.
sequelize
// add this as the second argument
// add this as the second argument
if
(
arguments
.
length
==
1
)
args
.
push
(
this
)
if
(
arguments
.
length
==
1
)
args
.
push
(
this
)
...
...
lib/model.js
View file @
a57bd01
...
@@ -22,7 +22,7 @@ module.exports = (function() {
...
@@ -22,7 +22,7 @@ module.exports = (function() {
Utils
.
_
.
extend
(
Model
.
prototype
,
Mixin
.
prototype
)
Utils
.
_
.
extend
(
Model
.
prototype
,
Mixin
.
prototype
)
Object
.
defineProperty
(
Model
.
prototype
,
'sequelize'
,
{
Object
.
defineProperty
(
Model
.
prototype
,
'sequelize'
,
{
get
:
function
(){
return
this
.
__factory
.
modelManager
.
sequelize
}
get
:
function
(){
return
this
.
__factory
.
model
Factory
Manager
.
sequelize
}
})
})
Object
.
defineProperty
(
Model
.
prototype
,
'QueryInterface'
,
{
Object
.
defineProperty
(
Model
.
prototype
,
'QueryInterface'
,
{
...
@@ -256,7 +256,7 @@ module.exports = (function() {
...
@@ -256,7 +256,7 @@ module.exports = (function() {
var
query
=
function
()
{
var
query
=
function
()
{
var
args
=
Utils
.
_
.
map
(
arguments
,
function
(
arg
,
_
)
{
return
arg
})
var
args
=
Utils
.
_
.
map
(
arguments
,
function
(
arg
,
_
)
{
return
arg
})
,
s
=
this
.
__factory
.
modelManager
.
sequelize
,
s
=
this
.
__factory
.
model
Factory
Manager
.
sequelize
args
.
push
(
this
)
args
.
push
(
this
)
return
s
.
query
.
apply
(
s
,
args
)
return
s
.
query
.
apply
(
s
,
args
)
...
...
lib/sequelize.js
View file @
a57bd01
var
Utils
=
require
(
"./utils"
)
var
Utils
=
require
(
"./utils"
)
,
ModelFactory
=
require
(
"./model-factory"
)
,
ModelFactory
=
require
(
"./model-factory"
)
,
DataTypes
=
require
(
'./data-types'
)
,
DataTypes
=
require
(
'./data-types'
)
,
Model
Manager
=
require
(
"./model
-manager"
)
,
Model
FactoryManager
=
require
(
"./model-factory
-manager"
)
,
Migrator
=
require
(
"./migrator"
)
,
Migrator
=
require
(
"./migrator"
)
,
QueryInterface
=
require
(
"./query-interface"
)
,
QueryInterface
=
require
(
"./query-interface"
)
...
@@ -26,7 +26,7 @@ module.exports = (function() {
...
@@ -26,7 +26,7 @@ module.exports = (function() {
var
ConnectorManager
=
require
(
"./dialects/"
+
this
.
options
.
dialect
+
"/connector-manager"
)
var
ConnectorManager
=
require
(
"./dialects/"
+
this
.
options
.
dialect
+
"/connector-manager"
)
this
.
model
Manager
=
new
Model
Manager
(
this
)
this
.
model
FactoryManager
=
new
ModelFactory
Manager
(
this
)
this
.
connectorManager
=
new
ConnectorManager
(
this
,
this
.
config
)
this
.
connectorManager
=
new
ConnectorManager
(
this
,
this
.
config
)
}
}
...
@@ -55,7 +55,7 @@ module.exports = (function() {
...
@@ -55,7 +55,7 @@ module.exports = (function() {
var
factory
=
new
ModelFactory
(
modelName
,
attributes
,
options
)
var
factory
=
new
ModelFactory
(
modelName
,
attributes
,
options
)
this
.
model
Manager
.
addModel
(
factory
.
init
(
this
.
model
Manager
))
this
.
model
FactoryManager
.
addModel
(
factory
.
init
(
this
.
modelFactory
Manager
))
return
factory
return
factory
}
}
...
@@ -89,7 +89,7 @@ module.exports = (function() {
...
@@ -89,7 +89,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
chainer
=
new
Utils
.
QueryChainer
var
chainer
=
new
Utils
.
QueryChainer
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
sync
(
options
))
})
self
.
model
Factory
Manager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
sync
(
options
))
})
chainer
chainer
.
run
()
.
run
()
...
@@ -104,7 +104,7 @@ module.exports = (function() {
...
@@ -104,7 +104,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
chainer
=
new
Utils
.
QueryChainer
var
chainer
=
new
Utils
.
QueryChainer
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
drop
())
})
self
.
model
Factory
Manager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
drop
())
})
chainer
chainer
.
run
()
.
run
()
...
...
spec/associations/has-many.spec.js
View file @
a57bd01
...
@@ -102,7 +102,7 @@ describe('HasMany', function() {
...
@@ -102,7 +102,7 @@ describe('HasMany', function() {
expect
(
Task
.
attributes
.
UserId
).
toBeUndefined
()
expect
(
Task
.
attributes
.
UserId
).
toBeUndefined
()
expect
(
User
.
attributes
.
UserId
).
toBeUndefined
()
expect
(
User
.
attributes
.
UserId
).
toBeUndefined
()
var
models
=
sequelize
.
modelManager
.
models
.
filter
(
function
(
model
)
{
var
models
=
sequelize
.
model
Factory
Manager
.
models
.
filter
(
function
(
model
)
{
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
})
})
...
@@ -122,7 +122,7 @@ describe('HasMany', function() {
...
@@ -122,7 +122,7 @@ describe('HasMany', function() {
expect
(
Task
.
attributes
.
user_id
).
toBeUndefined
()
expect
(
Task
.
attributes
.
user_id
).
toBeUndefined
()
expect
(
User
.
attributes
.
user_id
).
toBeUndefined
()
expect
(
User
.
attributes
.
user_id
).
toBeUndefined
()
var
models
=
sequelize
.
modelManager
.
models
.
filter
(
function
(
model
)
{
var
models
=
sequelize
.
model
Factory
Manager
.
models
.
filter
(
function
(
model
)
{
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
})
})
...
@@ -136,7 +136,7 @@ describe('HasMany', function() {
...
@@ -136,7 +136,7 @@ describe('HasMany', function() {
User
.
hasMany
(
Task
,
{
foreignKey
:
'person_id'
})
User
.
hasMany
(
Task
,
{
foreignKey
:
'person_id'
})
Task
.
hasMany
(
User
,
{
foreignKey
:
'work_item_id'
})
Task
.
hasMany
(
User
,
{
foreignKey
:
'work_item_id'
})
var
models
=
sequelize
.
modelManager
.
models
.
filter
(
function
(
model
)
{
var
models
=
sequelize
.
model
Factory
Manager
.
models
.
filter
(
function
(
model
)
{
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
return
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
})
})
...
@@ -227,7 +227,7 @@ describe('HasMany', function() {
...
@@ -227,7 +227,7 @@ describe('HasMany', function() {
Person
.
hasMany
(
Person
,
{
as
:
'CoWorkers'
})
Person
.
hasMany
(
Person
,
{
as
:
'CoWorkers'
})
Person
.
sync
({
force
:
true
}).
success
(
function
()
{
Person
.
sync
({
force
:
true
}).
success
(
function
()
{
var
modelNames
=
sequelize
.
modelManager
.
models
.
map
(
function
(
model
)
{
return
model
.
tableName
})
var
modelNames
=
sequelize
.
model
Factory
Manager
.
models
.
map
(
function
(
model
)
{
return
model
.
tableName
})
,
expectation
=
[
"Persons"
,
"ChildrenPersons"
,
"CoWorkersPersons"
,
"FriendsPersons"
]
,
expectation
=
[
"Persons"
,
"ChildrenPersons"
,
"CoWorkersPersons"
,
"FriendsPersons"
]
expectation
.
forEach
(
function
(
ex
)
{
expectation
.
forEach
(
function
(
ex
)
{
...
...
spec/config/factories.js
View file @
a57bd01
...
@@ -10,7 +10,7 @@ Factories.prototype.Model = function(modelName, options, callback, count) {
...
@@ -10,7 +10,7 @@ Factories.prototype.Model = function(modelName, options, callback, count) {
,
models
=
[]
,
models
=
[]
this
.
helpers
.
async
(
function
(
done
)
{
this
.
helpers
.
async
(
function
(
done
)
{
var
Model
=
self
.
sequelize
.
modelManager
.
getModel
(
modelName
)
var
Model
=
self
.
sequelize
.
model
Factory
Manager
.
getModel
(
modelName
)
var
create
=
function
(
cb
)
{
var
create
=
function
(
cb
)
{
Model
.
create
(
options
).
on
(
'success'
,
function
(
model
)
{
Model
.
create
(
options
).
on
(
'success'
,
function
(
model
)
{
...
...
spec/mysql/associations.spec.js
View file @
a57bd01
...
@@ -19,7 +19,7 @@ describe('Associations', function() {
...
@@ -19,7 +19,7 @@ describe('Associations', function() {
it
(
"should create a table wp_table1wp_table2s"
,
function
()
{
it
(
"should create a table wp_table1wp_table2s"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
expect
(
sequelize
.
modelManager
.
getModel
(
'wp_table1swp_table2s'
)).
toBeDefined
()
expect
(
sequelize
.
model
Factory
Manager
.
getModel
(
'wp_table1swp_table2s'
)).
toBeDefined
()
done
()
done
()
})
})
})
})
...
...
spec/sequelize.spec.js
View file @
a57bd01
...
@@ -36,9 +36,9 @@ describe('Sequelize', function() {
...
@@ -36,9 +36,9 @@ describe('Sequelize', function() {
describe
(
'define'
,
function
()
{
describe
(
'define'
,
function
()
{
it
(
"adds a new model to the model manager"
,
function
()
{
it
(
"adds a new model to the model manager"
,
function
()
{
expect
(
sequelize
.
modelManager
.
all
.
length
).
toEqual
(
0
)
expect
(
sequelize
.
model
Factory
Manager
.
all
.
length
).
toEqual
(
0
)
sequelize
.
define
(
'foo'
,
{
title
:
Sequelize
.
STRING
})
sequelize
.
define
(
'foo'
,
{
title
:
Sequelize
.
STRING
})
expect
(
sequelize
.
modelManager
.
all
.
length
).
toEqual
(
1
)
expect
(
sequelize
.
model
Factory
Manager
.
all
.
length
).
toEqual
(
1
)
})
})
})
})
...
...
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