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 cd3a58b1
authored
Jul 30, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use new manyToMany table if cross associated
1 parent
ae6f3bcb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
src/SequelizeTable.js
src/SequelizeTable.js
View file @
cd3a58b
...
@@ -42,7 +42,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -42,7 +42,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var
_attributes
=
{}
var
_attributes
=
{}
_attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
_attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
_attributes
[
association
.
table
.
identifier
]
=
Sequelize
.
INTEGER
_attributes
[
association
.
table
.
identifier
]
=
Sequelize
.
INTEGER
sequelize
.
define
(
[
table
.
tableName
,
association
.
table
.
tableName
].
sort
().
join
(
""
),
_attributes
)
sequelize
.
define
(
SequelizeHelper
.
SQL
.
manyToManyTableName
(
table
,
association
.
table
),
_attributes
)
}
else
{
}
else
{
// one to many relation
// one to many relation
association
.
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
association
.
table
.
attributes
[
table
.
identifier
]
=
Sequelize
.
INTEGER
...
@@ -94,7 +94,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -94,7 +94,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
result
.
forEach
(
function
(
resultSet
)
{
result
.
forEach
(
function
(
resultSet
)
{
objects
.
push
(
table
.
sqlResultToObject
(
resultSet
))
objects
.
push
(
table
.
sqlResultToObject
(
resultSet
))
})
})
if
(
_callback
)
_callback
(
objects
)
if
(
_callback
)
_callback
(
objects
)
...
@@ -132,10 +131,26 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -132,10 +131,26 @@ SequelizeTable = function(sequelize, tableName, attributes) {
type
:
'hasMany'
type
:
'hasMany'
})
})
table
.
prototype
[
assocName
]
=
function
(
callback
)
{
// don't check inside of method to increase performance
var
whereConditions
=
[
table
.
identifier
,
this
.
id
].
join
(
"="
)
if
(
_table
.
isCrossAssociatedWith
(
table
))
_table
.
findAll
({
where
:
whereConditions
},
callback
)
table
.
prototype
[
assocName
]
=
function
(
callback
)
{
}
var
whereConditions
=
[
table
.
identifier
,
this
.
id
].
join
(
"="
)
sequelize
.
tables
[
SequelizeHelper
.
SQL
.
manyToManyTableName
(
_table
,
table
)]
.
constructor
.
findAll
({
where
:
whereConditions
},
function
(
result
)
{
if
(
result
.
length
>
0
)
{
var
ids
=
[]
result
.
forEach
(
function
(
resultSet
)
{
ids
.
push
(
resultSet
.
id
)
})
_table
.
findAll
({
where
:
"id IN ("
+
ids
.
join
(
","
)
+
")"
},
callback
)
}
})
}
else
table
.
prototype
[
assocName
]
=
function
(
callback
)
{
var
whereConditions
=
[
table
.
identifier
,
this
.
id
].
join
(
"="
)
_table
.
findAll
({
where
:
whereConditions
},
callback
)
}
return
table
return
table
},
},
...
...
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