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 be6ab039
authored
Aug 14, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug with cross associated tables
1 parent
da77d30d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
src/SequelizeTable.js
test/SequelizeTableTest.js
src/SequelizeTable.js
View file @
be6ab03
...
...
@@ -22,17 +22,25 @@ SequelizeTable = function(sequelize, tableName, attributes) {
attributes
:
attributes
,
tableName
:
tableName
,
is
CrossAssociatedWith
:
function
(
associatedTabl
e
)
{
is
AssociatedWith
:
function
(
anotherTable
,
associationTyp
e
)
{
var
result
=
false
var
myTableName
=
table
.
tableName
associatedTable
.
associations
.
forEach
(
function
(
association
)
{
if
((
association
.
table
.
tableName
==
myTableName
)
&&
(
association
.
type
==
'hasMany'
))
result
=
true
var
associations
=
SequelizeHelper
.
Array
.
select
(
table
.
associations
,
function
(
assoc
)
{
return
assoc
.
table
.
tableName
==
anotherTable
.
tableName
})
if
(
associations
.
length
>
0
)
{
if
(
associationType
)
result
=
(
associations
[
0
].
type
==
associationType
)
else
result
=
true
}
return
result
},
isCrossAssociatedWith
:
function
(
anotherTable
)
{
return
table
.
isAssociatedWith
(
anotherTable
,
'hasMany'
)
&&
anotherTable
.
isAssociatedWith
(
table
,
'hasMany'
)
},
prepareAssociations
:
function
(
callback
)
{
table
.
associations
.
forEach
(
function
(
association
)
{
switch
(
association
.
type
)
{
...
...
test/SequelizeTableTest.js
View file @
be6ab03
...
...
@@ -218,7 +218,6 @@ module.exports = {
var
task
=
new
Task
({
title
:
'do smth'
})
var
deadline
=
new
Deadline
({
date
:
new
Date
()})
var
assertMe
=
null
Sequelize
.
chainQueries
([{
drop
:
s2
},
{
sync
:
s2
}],
function
()
{
task
.
save
(
function
()
{
...
...
@@ -292,5 +291,15 @@ module.exports = {
beforeExit
(
function
()
{
assert
.
isNull
(
subject
)
})
},
'isAssociatedWith'
:
function
(
assert
,
beforeExit
)
{
var
IsAssociatedWithTestOne
=
s
.
define
(
"IsAssociatedWithTestOne"
,
{})
var
IsAssociatedWithTestTwo
=
s
.
define
(
"IsAssociatedWithTestTwo"
,
{})
IsAssociatedWithTestOne
.
belongsTo
(
'foo'
,
IsAssociatedWithTestTwo
)
assert
.
equal
(
true
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
))
assert
.
equal
(
true
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'belongsTo'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasMany'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasOne'
))
}
}
\ 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