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 1f89402e
authored
Apr 25, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some convenience stuff
1 parent
803192aa
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
8 deletions
lib/sequelize/associations/has-many.js
lib/sequelize/sequelize.js
lib/sequelize/utils.js
test/Model/belongsTo.js
test/config.js
lib/sequelize/associations/has-many.js
View file @
1f89402
var
Utils
=
require
(
"./../utils"
)
,
DataTypes
=
require
(
'./../data-types'
)
,
QueryChainer
=
require
(
"./../query-chainer"
)
var
HasMany
=
module
.
exports
=
function
(
srcModel
,
targetModel
,
options
)
{
this
.
source
=
srcModel
...
...
@@ -78,7 +77,7 @@ HasMany.prototype.injectSetter = function(obj) {
instance
[
self
.
accessors
.
get
]().
on
(
'success'
,
function
(
oldAssociatedObjects
)
{
if
(
self
.
connectorModel
)
{
var
foreignIdentifier
=
self
.
target
.
associations
[
self
.
source
.
tableName
].
identifier
var
destroyChainer
=
new
QueryChainer
var
destroyChainer
=
new
Utils
.
QueryChainer
// destroy the old association objects
oldAssociatedObjects
.
forEach
(
function
(
associatedObject
)
{
destroyChainer
.
add
(
associatedObject
.
destroy
())
})
destroyChainer
...
...
@@ -87,7 +86,7 @@ HasMany.prototype.injectSetter = function(obj) {
.
on
(
'success'
,
function
()
{
// create new one
var
createChainer
=
new
QueryChainer
var
createChainer
=
new
Utils
.
QueryChainer
newAssociatedObjects
.
forEach
(
function
(
associatedObject
)
{
var
attributes
=
{}
attributes
[
self
.
identifier
]
=
instance
.
id
...
...
@@ -110,7 +109,7 @@ HasMany.prototype.injectSetter = function(obj) {
})
// set the new one
var
chainer
=
new
QueryChainer
var
chainer
=
new
Utils
.
QueryChainer
newAssociatedObjects
.
forEach
(
function
(
associatedObject
)
{
associatedObject
[
self
.
identifier
]
=
instance
.
id
chainer
.
add
(
associatedObject
.
save
())
...
...
lib/sequelize/sequelize.js
View file @
1f89402
...
...
@@ -19,6 +19,7 @@ var Sequelize = module.exports = function(database, username, password, options)
port
:
options
.
port
||
3306
}
}
Sequelize
.
Utils
=
Utils
var
instanceMethods
=
{
define
:
function
(
modelName
,
attributes
,
options
)
{
...
...
@@ -37,5 +38,5 @@ var instanceMethods = {
}
Utils
.
_
.
map
(
require
(
'./data-types'
),
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Utils
.
_
.
map
(
instanceMethods
,
function
(
fct
,
name
)
{
Sequelize
.
prototype
[
name
]
=
fct
})
\ No newline at end of file
Sequelize
.
Utils
.
_
.
map
(
require
(
'./data-types'
),
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
Utils
.
_
.
map
(
instanceMethods
,
function
(
fct
,
name
)
{
Sequelize
.
prototype
[
name
]
=
fct
})
\ No newline at end of file
lib/sequelize/utils.js
View file @
1f89402
...
...
@@ -128,6 +128,7 @@ var Utils = module.exports = {
}
}
// Some nice class accessors
var
CustomEventEmitter
=
Utils
.
CustomEventEmitter
=
function
(
fct
)
{
this
.
fct
=
fct
}
...
...
@@ -138,3 +139,5 @@ CustomEventEmitter.prototype.run = function() {
setTimeout
(
function
(){
self
.
fct
()
},
5
)
// delay the function call and return the emitter
return
this
}
Utils
.
QueryChainer
=
require
(
"./query-chainer"
)
\ No newline at end of file
test/Model/belongsTo.js
View file @
1f89402
test/config.js
View file @
1f89402
module
.
exports
=
{
username
:
'root'
,
password
:
null
,
database
:
'sequelize_test'
database
:
'sequelize_test'
,
host
:
'127.0.0.1'
}
\ No newline at end of file
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