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 df5b611e
authored
Aug 04, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring on many to many association setting
1 parent
e60f8233
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
src/SequelizeTable.js
src/SequelizeTable.js
View file @
df5b611
...
...
@@ -91,12 +91,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
sequelize
.
query
(
Sequelize
.
sqlQueryFor
(
'select'
,
queryOptions
),
function
(
result
)
{
var
objects
=
[]
result
.
forEach
(
function
(
resultSet
)
{
objects
.
push
(
table
.
sqlResultToObject
(
resultSet
))
})
var
objects
=
SequelizeHelper
.
Array
.
map
(
result
,
function
(
r
)
{
return
table
.
sqlResultToObject
(
r
)
})
if
(
_callback
)
_callback
(
objects
)
}
)
...
...
@@ -143,19 +138,21 @@ SequelizeTable = function(sequelize, tableName, attributes) {
result
.
forEach
(
function
(
resultSet
)
{
ids
.
push
(
resultSet
.
id
)
})
_table
.
findAll
({
where
:
"id IN ("
+
ids
.
join
(
","
)
+
")"
},
callback
)
}
else
{
if
(
callback
)
callback
([])
}
})
}
table
.
prototype
[
SequelizeHelper
.
SQL
.
addPrefix
(
'set'
,
assocName
)]
=
function
(
objects
,
callback
)
{
var
objectIds
=
SequelizeHelper
.
Array
.
map
(
objects
,
function
(
obj
)
{
return
obj
.
id
})
var
Association
=
sequelize
.
tables
[
SequelizeHelper
.
SQL
.
manyToManyTableName
(
_table
,
table
)].
klass
var
self
=
this
var
Association
=
sequelize
.
tables
[
SequelizeHelper
.
SQL
.
manyToManyTableName
(
_table
,
table
)].
klass
var
currentAssociations
=
null
var
objectIds
=
SequelizeHelper
.
Array
.
map
(
objects
,
function
(
obj
)
{
return
obj
.
id
})
var
getAssociatedObjects
=
function
(
callback
)
{
self
[
assocName
](
function
(
associations
)
{
currentAssociations
=
associations
callback
()
callback
(
associations
)
})
}
var
deleteObsoleteAssociations
=
function
(
callback
)
{
...
...
@@ -163,8 +160,11 @@ SequelizeTable = function(sequelize, tableName, attributes) {
currentAssociations
.
forEach
(
function
(
association
)
{
if
(
objectIds
.
indexOf
(
association
.
id
)
==
-
1
)
obsolete
.
push
(
association
.
id
)
})
if
(
obsolete
.
length
==
0
)
callback
([])
else
sequelize
.
query
(
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
Association
.
tableName
,
where
:
"id IN ("
+
obsolete
.
join
(
","
)
+
")"
}),
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
Association
.
tableName
,
where
:
"id IN ("
+
obsolete
.
join
(
","
)
+
")"
,
limit
:
null
}),
function
(){
callback
(
obsolete
)
}
)
}
...
...
@@ -178,8 +178,8 @@ SequelizeTable = function(sequelize, tableName, attributes) {
if
((
o
instanceof
_table
)
&&
(
self
.
id
!=
null
)
&&
(
o
.
id
!=
null
))
{
var
attributes
=
{}
attributes
[
self
.
table
.
identifier
]
=
self
.
id
attributes
[
o
bject
.
table
.
identifier
]
=
o
.
id
savings
.
push
(
new
Association
(
attributes
).
save
)
attributes
[
o
.
table
.
identifier
]
=
o
.
id
savings
.
push
(
{
save
:
new
Association
(
attributes
)}
)
}
})
Sequelize
.
chainQueries
(
savings
,
function
()
{
...
...
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