Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
cff3c430
Commit
cff3c430
authored
Jun 26, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL: improved self-reference handling
parent
8c4d8293
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
12 deletions
+98
-12
Query.php
Doctrine/Query.php
+10
-5
Record.php
Doctrine/Record.php
+4
-3
QueryTestCase.php
tests/QueryTestCase.php
+83
-4
classes.php
tests/classes.php
+1
-0
No files found.
Doctrine/Query.php
View file @
cff3c430
...
...
@@ -524,7 +524,6 @@ class Doctrine_Query extends Doctrine_Access {
if
(
!
isset
(
$previd
[
$name
]))
$previd
[
$name
]
=
array
();
if
(
$previd
[
$name
]
!==
$row
)
{
// set internal data
...
...
@@ -536,6 +535,8 @@ class Doctrine_Query extends Doctrine_Access {
if
(
$name
==
$root
)
{
// add record into root collection
$coll
->
add
(
$record
);
unset
(
$previd
);
}
else
{
$pointer
=
$this
->
joins
[
$name
];
...
...
@@ -549,15 +550,17 @@ class Doctrine_Query extends Doctrine_Access {
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
ONE_AGGREGATE
:
// one-to-one relation
$last
->
internalSet
(
$fk
->
getLocal
(),
$record
->
getID
());
$last
->
initSingleReference
(
$record
);
$last
->
initSingleReference
(
$record
,
$fk
);
$prev
[
$name
]
=
$record
;
break
;
default
:
// one-to-many relation or many-to-many relation
if
(
!
$last
->
hasReference
(
$alias
))
{
...
...
@@ -1059,9 +1062,9 @@ class Doctrine_Query extends Doctrine_Access {
* @return string
*/
final
public
function
generateAlias
(
$tableName
)
{
if
(
isset
(
$this
->
tableIndexes
[
$tableName
]))
if
(
isset
(
$this
->
tableIndexes
[
$tableName
]))
{
return
$tableName
.++
$this
->
tableIndexes
[
$tableName
];
else
{
}
else
{
$this
->
tableIndexes
[
$tableName
]
=
1
;
return
$tableName
;
}
...
...
@@ -1106,7 +1109,9 @@ class Doctrine_Query extends Doctrine_Access {
$table
=
$this
->
session
->
getTable
(
$name
);
$tname
=
$table
->
getTableName
();
$this
->
tableIndexes
[
$tname
]
=
1
;
if
(
!
isset
(
$this
->
tableAliases
[
$currPath
]))
$this
->
tableIndexes
[
$tname
]
=
1
;
$this
->
parts
[
"from"
][
$tname
]
=
true
;
...
...
Doctrine/Record.php
View file @
cff3c430
...
...
@@ -991,9 +991,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param Doctrine_Relation $connector
* @return void
*/
public
function
initSingleReference
(
Doctrine_Record
$record
)
{
$name
=
$this
->
table
->
getAlias
(
$record
->
getTable
()
->
getComponentName
());
$this
->
references
[
$name
]
=
$record
;
public
function
initSingleReference
(
Doctrine_Record
$record
,
Doctrine_Relation
$connector
)
{
$alias
=
$connector
->
getAlias
();
$this
->
references
[
$alias
]
=
$record
;
}
/**
* initalizes a one-to-many / many-to-many relation
...
...
tests/QueryTestCase.php
View file @
cff3c430
...
...
@@ -26,6 +26,8 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
}
public
function
testSelfReferencing
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$category
=
new
Forum_Category
();
$category
->
name
=
"Root"
;
...
...
@@ -38,6 +40,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
session
->
flush
();
$this
->
session
->
clear
();
$category
=
$category
->
getTable
()
->
find
(
$category
->
id
);
$this
->
assertEqual
(
$category
->
name
,
"Root"
);
...
...
@@ -49,23 +52,99 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
Subcategory
[
1
]
->
name
,
"Sub 2 Sub 2"
);
$this
->
session
->
clear
();
$query
->
from
(
"Forum_Category.Subcategory.Subcategory"
);
$coll
=
$query
->
execute
();
$category
=
$coll
[
0
];
$count
=
count
(
$this
->
dbh
);
$this
->
assertEqual
(
$category
->
name
,
"Root"
);
$query
=
new
Doctrine_Query
(
$this
->
session
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
name
,
"Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
name
,
"Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
Subcategory
[
0
]
->
name
,
"Sub 1 Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
Subcategory
[
1
]
->
name
,
"Sub 1 Sub 2"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
Subcategory
[
0
]
->
name
,
"Sub 2 Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
Subcategory
[
1
]
->
name
,
"Sub 2 Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
session
->
clear
();
$query
->
from
(
"Forum_Category.Parent.Parent"
)
->
where
(
"Forum_Category.name LIKE 'Sub%Sub%'"
);
$coll
=
$query
->
execute
();
$count
=
count
(
$this
->
dbh
);
$this
->
assertEqual
(
$coll
->
count
(),
4
);
$this
->
assertEqual
(
$coll
[
0
]
->
name
,
"Sub 1 Sub 1"
);
$this
->
assertEqual
(
$coll
[
1
]
->
name
,
"Sub 1 Sub 2"
);
$this
->
assertEqual
(
$coll
[
2
]
->
name
,
"Sub 2 Sub 1"
);
$this
->
assertEqual
(
$coll
[
3
]
->
name
,
"Sub 2 Sub 2"
);
$query
->
from
(
"Forum_Category.Subcategory.Subcategory"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$coll
[
0
]
->
Parent
->
name
,
"Sub 1"
);
$this
->
assertEqual
(
$coll
[
1
]
->
Parent
->
name
,
"Sub 1"
);
$this
->
assertEqual
(
$coll
[
2
]
->
Parent
->
name
,
"Sub 2"
);
$this
->
assertEqual
(
$coll
[
3
]
->
Parent
->
name
,
"Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$coll
[
0
]
->
Parent
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$coll
[
1
]
->
Parent
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$coll
[
2
]
->
Parent
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$coll
[
3
]
->
Parent
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$query
->
from
(
"Forum_Category.Parent, Forum_Category.Subcategory"
)
->
where
(
"Forum_Category.name = 'Sub 1' OR Forum_Category.name = 'Sub 2'"
);
$coll
=
$query
->
execute
();
$category
=
$coll
[
0
];
$count
=
count
(
$this
->
dbh
);
$this
->
assertEqual
(
$coll
->
count
(),
2
);
$this
->
assertEqual
(
$coll
[
0
]
->
name
,
"Sub 1"
);
$this
->
assertEqual
(
$coll
[
1
]
->
name
,
"Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$coll
[
0
]
->
Subcategory
[
0
]
->
name
,
"Sub 1 Sub 1"
);
$this
->
assertEqual
(
$coll
[
0
]
->
Subcategory
[
1
]
->
name
,
"Sub 1 Sub 2"
);
$this
->
assertEqual
(
$coll
[
1
]
->
Subcategory
[
0
]
->
name
,
"Sub 2 Sub 1"
);
$this
->
assertEqual
(
$coll
[
1
]
->
Subcategory
[
1
]
->
name
,
"Sub 2 Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$coll
[
0
]
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$coll
[
1
]
->
Parent
->
name
,
"Root"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
session
->
clear
();
$query
->
from
(
"Forum_Category.Subcategory.Subcategory"
)
->
where
(
"Forum_Category.parent_category_id IS NULL"
);
$coll
=
$query
->
execute
();
$this
->
assertEqual
(
$coll
->
count
(),
1
);
$count
=
count
(
$this
->
dbh
);
$this
->
assertEqual
(
$category
->
name
,
"Root"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
name
,
"Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
name
,
"Sub 2"
);
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
Subcategory
[
0
]
->
name
,
"Sub 1 Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
0
]
->
Subcategory
[
1
]
->
name
,
"Sub 1 Sub 2"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
Subcategory
[
0
]
->
name
,
"Sub 2 Sub 1"
);
$this
->
assertEqual
(
$category
->
Subcategory
[
1
]
->
Subcategory
[
1
]
->
name
,
"Sub 2 Sub 2"
);
$this
->
assertEqual
(
(
$count
+
1
)
,
count
(
$this
->
dbh
));
$this
->
assertEqual
(
$count
,
count
(
$this
->
dbh
));
}
public
function
testGetPath
()
{
...
...
tests/classes.php
View file @
cff3c430
...
...
@@ -180,6 +180,7 @@ class Forum_Category extends Doctrine_Record {
}
public
function
setUp
()
{
$this
->
hasMany
(
"Forum_Category as Subcategory"
,
"Subcategory.parent_category_id"
);
$this
->
hasOne
(
"Forum_Category as Parent"
,
"Forum_Category.parent_category_id"
);
$this
->
hasOne
(
"Forum_Category as Rootcategory"
,
"Forum_Category.root_category_id"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment