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
e75f3598
Commit
e75f3598
authored
Aug 15, 2006
by
pookey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relation fetching refactoring
parent
76081664
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
44 deletions
+61
-44
Association.php
Doctrine/Association.php
+22
-0
Collection.php
Doctrine/Collection.php
+10
-31
Record.php
Doctrine/Record.php
+1
-5
Relation.php
Doctrine/Relation.php
+18
-6
CollectionTestCase.php
tests/CollectionTestCase.php
+7
-0
run.php
tests/run.php
+3
-2
No files found.
Doctrine/Association.php
View file @
e75f3598
...
...
@@ -34,5 +34,27 @@ class Doctrine_Association extends Doctrine_Relation {
public
function
getAssociationFactory
()
{
return
$this
->
associationTable
;
}
/**
* getRelationDql
*
* @param integer $count
* @return string
*/
public
function
getRelationDql
(
$count
,
$context
=
'record'
)
{
$sub
=
"SELECT "
.
$this
->
foreign
.
" FROM "
.
$this
->
associationTable
->
getTableName
()
.
" WHERE "
.
$this
->
local
.
" IN ("
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
")"
;
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
();
if
(
$context
!=
'record'
)
$dql
.=
":"
.
$this
->
associationTable
->
getComponentName
();
$dql
.=
" WHERE "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
table
->
getIdentifier
()
.
" IN (
$sub
)"
;
return
$dql
;
}
}
?>
Doctrine/Collection.php
View file @
e75f3598
...
...
@@ -488,13 +488,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/**
* loadRelated
*
* @param
string
$name
* @param
mixed
$name
*/
public
function
loadRelated
(
$name
)
{
public
function
loadRelated
(
$name
=
null
)
{
$query
=
new
Doctrine_Query
(
$this
->
table
->
getSession
());
$rel
=
$this
->
table
->
getForeignKey
(
$name
);
$table
=
$rel
->
getTable
();
$query
=
new
Doctrine_Query
(
$this
->
table
->
getSession
());
if
(
!
isset
(
$name
))
return
$query
;
$rel
=
$this
->
table
->
getForeignKey
(
$name
);
$table
=
$rel
->
getTable
();
$foreign
=
$rel
->
getForeign
();
$local
=
$rel
->
getLocal
();
...
...
@@ -510,32 +513,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list
[]
=
$value
;
endforeach
;
}
$paramStr
=
"("
.
substr
(
str_repeat
(
"?, "
,
count
(
$list
)),
0
,
-
2
)
.
")"
;
$multi
=
true
;
if
(
$rel
instanceof
Doctrine_LocalKey
||
$rel
instanceof
Doctrine_ForeignKey
)
$dql
=
"FROM "
.
$table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$rel
->
getForeign
()
.
" IN "
.
$paramStr
;
if
(
$rel
instanceof
Doctrine_LocalKey
)
{
$multi
=
false
;
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
$asf
=
$rel
->
getAssociationFactory
();
$sub
=
"SELECT "
.
$foreign
.
" FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$local
.
" IN "
.
$paramStr
;
$table
->
getForeignKey
(
$table
->
getAlias
(
$this
->
table
->
getComponentName
()));
$dql
=
"FROM "
.
$table
->
getComponentName
()
.
":"
.
$asf
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$table
->
getIdentifier
()
.
" IN (
$sub
)"
;
//$query->parseQuery($dql);
//print Doctrine_Lib::formatSql($query->getQuery());
}
$dql
=
$rel
->
getRelationDql
(
count
(
$list
),
'collection'
);
$coll
=
$query
->
query
(
$dql
,
$list
);
...
...
@@ -567,6 +545,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
$identifier
=
$this
->
table
->
getIdentifier
();
$asf
=
$rel
->
getAssociationFactory
();
foreach
(
$this
->
data
as
$key
=>
$record
)
{
if
(
$record
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
||
...
...
Doctrine/Record.php
View file @
e75f3598
...
...
@@ -1153,11 +1153,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
)"
;
$query
=
$fk
->
getRelationDql
(
1
);
$coll
=
$graph
->
query
(
$query
,
array
(
$this
->
getIncremented
()));
...
...
Doctrine/Relation.php
View file @
e75f3598
...
...
@@ -52,23 +52,23 @@ class Doctrine_Relation {
/**
* @var Doctrine_Table $table foreign factory
*/
pr
ivate
$table
;
pr
otected
$table
;
/**
* @var string $local local field
*/
pr
ivate
$local
;
pr
otected
$local
;
/**
* @var string $foreign foreign field
*/
pr
ivate
$foreign
;
pr
otected
$foreign
;
/**
* @var integer $type bind type
*/
pr
ivate
$type
;
pr
otected
$type
;
/**
* @var string $alias relation alias
*/
pr
ivate
$alias
;
pr
otected
$alias
;
/**
* @param Doctrine_Table $table
...
...
@@ -115,7 +115,19 @@ class Doctrine_Relation {
final
public
function
getForeign
()
{
return
$this
->
foreign
;
}
/**
* getRelationDql
*
* @param integer $count
* @return string
*/
public
function
getRelationDql
(
$count
)
{
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
()
.
" WHERE "
.
$this
->
table
->
getComponentName
()
.
'.'
.
$this
->
foreign
.
" IN ("
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
")"
;
return
$dql
;
}
/**
* getDeleteOperations
*
...
...
tests/CollectionTestCase.php
View file @
e75f3598
...
...
@@ -14,6 +14,13 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$coll
->
count
(),
3
);
$this
->
assertEqual
(
$coll
->
getKeys
(),
array
(
0
,
1
,
2
));
}
public
function
testLoadRelated
()
{
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$q
=
$coll
->
loadRelated
();
$this
->
assertTrue
(
$q
instanceof
Doctrine_Query
);
}
public
function
testLoadRelatedForAssociation
()
{
$coll
=
$this
->
session
->
query
(
"FROM User"
);
...
...
tests/run.php
View file @
e75f3598
...
...
@@ -46,8 +46,6 @@ $test->addTestCase(new Doctrine_ConfigurableTestCase());
$test
->
addTestCase
(
new
Doctrine_Collection_OffsetTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_PessimisticLockingTestCase
());
$test
->
addTestCase
(
new
Doctrine_ViewTestCase
());
...
...
@@ -65,6 +63,9 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
//$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