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
ffa3a238
Commit
ffa3a238
authored
Jun 08, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preliminary support for many-to-many fetching with column aggregation inheritance
parent
c3f186c2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
17 deletions
+67
-17
Query.php
Doctrine/Query.php
+32
-10
Record.php
Doctrine/Record.php
+1
-1
Table.php
Doctrine/Table.php
+14
-1
QueryTestCase.php
tests/QueryTestCase.php
+18
-4
run.php
tests/run.php
+2
-1
No files found.
Doctrine/Query.php
View file @
ffa3a238
...
...
@@ -41,6 +41,14 @@ class Doctrine_Query extends Doctrine_Access {
* @var array $connectors component connectors
*/
private
$connectors
=
array
();
/**
* @var array $tableAliases
*/
private
$tableAliases
=
array
();
/**
* @var array $tableIndexes
*/
private
$tableIndexes
=
array
();
/**
* @var array $dql DQL query string parts
*/
...
...
@@ -140,16 +148,18 @@ class Doctrine_Query extends Doctrine_Access {
default
:
throw
new
Doctrine_Exception
(
"Unknown fetchmode."
);
endswitch
;
$cname
=
$table
->
getComponentName
();
$this
->
fetchModes
[
$cname
]
=
$fetchmode
;
$tablename
=
$table
->
getTableName
();
$component
=
$table
->
getComponentName
();
$this
->
fetchModes
[
$component
]
=
$fetchmode
;
$tablename
=
$this
->
tableAliases
[
$component
];
$count
=
count
(
$this
->
tables
);
foreach
(
$names
as
$name
)
{
if
(
$count
==
0
)
{
$this
->
parts
[
"columns"
][]
=
$tablename
.
"."
.
$name
;
}
else
{
$this
->
parts
[
"columns"
][]
=
$tablename
.
"."
.
$name
.
" AS "
.
$c
name
.
"__"
.
$name
;
$this
->
parts
[
"columns"
][]
=
$tablename
.
"."
.
$name
.
" AS "
.
$c
omponent
.
"__"
.
$name
;
}
}
}
...
...
@@ -317,9 +327,10 @@ class Doctrine_Query extends Doctrine_Access {
// get the inheritance maps
$array
=
array
();
foreach
(
$this
->
tables
as
$objTable
)
:
$tname
=
$objTable
->
getTableName
();
$array
[
$tname
][]
=
$objTable
->
getInheritanceMap
();
foreach
(
$this
->
tables
as
$table
)
:
$component
=
$table
->
getComponentName
();
$tableName
=
$this
->
tableAliases
[
$component
];
$array
[
$tableName
][]
=
$table
->
getInheritanceMap
();
endforeach
;
// apply inheritance maps
...
...
@@ -330,7 +341,7 @@ class Doctrine_Query extends Doctrine_Access {
$a
=
array
();
foreach
(
$maps
as
$map
)
{
$b
=
array
();
foreach
(
$map
as
$field
=>
$value
)
{
foreach
(
$map
as
$field
=>
$value
)
{
$b
[]
=
$tname
.
".
$field
=
$value
"
;
}
if
(
!
empty
(
$b
))
$a
[]
=
implode
(
" AND "
,
$b
);
...
...
@@ -390,6 +401,7 @@ class Doctrine_Query extends Doctrine_Access {
$keys
=
array_keys
(
$this
->
tables
);
$name
=
$this
->
tables
[
$keys
[
0
]]
->
getComponentName
();
$stmt
=
$this
->
session
->
execute
(
$query
,
$params
);
...
...
@@ -922,6 +934,7 @@ class Doctrine_Query extends Doctrine_Access {
$tname
=
$table
->
getTableName
();
$this
->
parts
[
"from"
][
$tname
]
=
true
;
$this
->
tableAliases
[
$name
]
=
$tname
;
}
else
{
$index
+=
strlen
(
$e
[(
$key
-
1
)])
+
1
;
...
...
@@ -952,7 +965,7 @@ class Doctrine_Query extends Doctrine_Access {
if
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
$this
->
parts
[
"join"
][
$tname
][
$tname2
]
=
$join
.
$tname2
.
" ON "
.
$tname
.
"."
.
$fk
->
getLocal
()
.
" = "
.
$tname2
.
"."
.
$fk
->
getForeign
();
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
...
...
@@ -961,14 +974,23 @@ class Doctrine_Query extends Doctrine_Access {
$assocTableName
=
$asf
->
getTableName
();
$this
->
parts
[
"join"
][
$tname
][
$assocTableName
]
=
$join
.
$assocTableName
.
" ON "
.
$tname
.
".id = "
.
$assocTableName
.
"."
.
$fk
->
getLocal
();
$this
->
parts
[
"join"
][
$tname
][
$tname2
]
=
$join
.
$tname2
.
" ON "
.
$tname2
.
".id = "
.
$assocTableName
.
"."
.
$fk
->
getForeign
();
if
(
$tname
==
$tname2
)
{
$tname2
=
$tname
.
"2"
;
$alias
=
$tname
.
" AS "
.
$tname2
;
}
else
$alias
=
$tname2
;
$this
->
parts
[
"join"
][
$tname
][
$tname2
]
=
$join
.
$alias
.
" ON "
.
$tname2
.
".id = "
.
$assocTableName
.
"."
.
$fk
->
getForeign
();
}
$c
=
$table
->
getComponentName
();
$this
->
joins
[
$name
]
=
$c
;
$table
=
$fk
->
getTable
();
$this
->
tableAliases
[
$name
]
=
$tname2
;
}
if
(
!
isset
(
$this
->
tables
[
$name
]))
{
...
...
Doctrine/Record.php
View file @
ffa3a238
...
...
@@ -1098,7 +1098,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
$asf
=
$fk
->
getAssociationFactory
();
$query
=
"SELECT "
.
$foreign
.
" FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$local
.
" = ?"
;
$graph
=
new
Doctrine_Query
(
$table
->
getSession
());
$query
=
"FROM "
.
$table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$table
->
getIdentifier
()
.
" IN (
$query
)"
;
...
...
Doctrine/Table.php
View file @
ffa3a238
...
...
@@ -87,7 +87,8 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
private
$boundAliases
=
array
();
/**
* @var integer $columnCount cached column count
* @var integer $columnCount cached column count, Doctrine_Record uses this column count in when
* determining its state
*/
private
$columnCount
;
...
...
@@ -323,6 +324,18 @@ class Doctrine_Table extends Doctrine_Configurable {
final
public
function
getSequenceName
()
{
return
$this
->
sequenceName
;
}
/**
* getParents
*/
final
public
function
getParents
()
{
return
$this
->
parents
;
}
/**
* @return boolean
*/
final
public
function
hasInheritanceMap
()
{
return
(
empty
(
$this
->
inheritanceMap
));
}
/**
* setInheritanceMap
* @param array $inheritanceMap
...
...
tests/QueryTestCase.php
View file @
ffa3a238
...
...
@@ -14,7 +14,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
dbh
->
query
(
"DROP TABLE IF EXISTS test_entries"
);
parent
::
prepareTables
();
}
//public function prepareData() { }
public
function
testManyToManyFetchingWithColumnAggregationInheritance
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$query
->
from
(
'User-l:Group-l'
);
$users
=
$query
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$users
[
0
]
->
Group
->
count
(),
1
);
$query
->
from
(
'User-l.Group-l'
);
$users
=
$query
->
execute
();
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
[
0
]
->
Group
->
count
(),
0
);
$this
->
assertEqual
(
$users
[
1
]
->
Group
->
count
(),
1
);
$this
->
assertEqual
(
$users
[
2
]
->
Group
->
count
(),
0
);
}
public
function
testManyToManyFetchingWithColonOperator
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
...
...
@@ -77,7 +92,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$tasks
[
1
]
->
ResourceAlias
[
1
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$this
->
assertEqual
(
$tasks
[
1
]
->
ResourceAlias
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$this
->
assertEqual
(
$tasks
[
1
]
->
ResourceAlias
[
3
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$count
=
count
(
$this
->
dbh
);
$this
->
assertEqual
(
$tasks
[
1
]
->
ResourceAlias
[
0
]
->
name
,
"R3"
);
...
...
@@ -90,6 +105,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$tasks
[
2
]
->
ResourceAlias
->
count
(),
1
);
$this
->
assertTrue
(
$tasks
[
2
]
->
ResourceAlias
instanceof
Doctrine_Collection_Lazy
);
}
public
function
testManyToManyFetchingWithDotOperator
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
...
...
@@ -847,7 +863,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max']));
}
}
?>
tests/run.php
View file @
ffa3a238
...
...
@@ -44,9 +44,10 @@ $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_PessimisticLockingTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_PessimisticLockingTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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