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
83d89b76
Commit
83d89b76
authored
Jan 04, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TreeStructure bug fixed
parent
b6368617
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
13 deletions
+50
-13
Record.php
lib/Doctrine/Record.php
+5
-3
Relation.php
lib/Doctrine/Relation.php
+3
-3
ForeignKey.php
lib/Doctrine/Relation/ForeignKey.php
+6
-2
Table.php
lib/Doctrine/Table.php
+11
-0
TreeStructureTestCase.php
tests/TreeStructureTestCase.php
+23
-3
run.php
tests/run.php
+2
-2
No files found.
lib/Doctrine/Record.php
View file @
83d89b76
...
...
@@ -1315,10 +1315,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
final
public
function
loadReference
(
$name
)
{
$fk
=
$this
->
_table
->
getRelation
(
$name
);
if
(
$fk
->
isOneToOne
())
{
$this
->
references
[
$name
]
=
$fk
->
fetchRelatedFor
(
$this
);
}
else
{
$coll
=
$fk
->
fetchRelatedFor
(
$this
);
...
...
@@ -1344,7 +1346,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
ownsMany
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
final
public
function
ownsMany
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_COMPOSITE
,
$localKey
);
}
...
...
@@ -1355,7 +1357,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
hasOne
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
final
public
function
hasOne
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_AGGREGATE
,
$localKey
);
}
...
...
@@ -1366,7 +1368,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
hasMany
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
final
public
function
hasMany
(
$componentName
,
$foreignKey
,
$localKey
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_AGGREGATE
,
$localKey
);
}
...
...
lib/Doctrine/Relation.php
View file @
83d89b76
...
...
@@ -171,9 +171,9 @@ abstract class Doctrine_Relation
*/
public
function
getRelationDql
(
$count
)
{
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
()
.
" WHERE "
.
$this
->
table
->
getComponentName
()
.
'.'
.
$this
->
foreign
.
" IN ("
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
")"
;
$dql
=
'FROM '
.
$this
->
table
->
getComponentName
()
.
' WHERE '
.
$this
->
table
->
getComponentName
()
.
'.'
.
$this
->
foreign
.
' IN ('
.
substr
(
str_repeat
(
'?, '
,
$count
),
0
,
-
2
)
.
')'
;
return
$dql
;
}
...
...
lib/Doctrine/Relation/ForeignKey.php
View file @
83d89b76
...
...
@@ -81,14 +81,18 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
if
(
empty
(
$id
))
{
$related
=
$this
->
table
->
create
();
}
else
{
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
()
.
" WHERE "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
foreign
.
" = ?"
;
$dql
=
'FROM '
.
$this
->
table
->
getComponentName
()
.
' WHERE '
.
$this
->
table
->
getComponentName
()
.
'.'
.
$this
->
foreign
.
' = ?'
;
$coll
=
$this
->
table
->
getConnection
()
->
query
(
$dql
,
array
(
$id
));
$related
=
$coll
[
0
];
}
$related
->
set
(
$this
->
foreign
,
$record
,
false
);
}
else
{
}
else
{
if
(
empty
(
$id
))
{
$related
=
new
Doctrine_Collection
(
$this
->
table
);
}
else
{
...
...
lib/Doctrine/Table.php
View file @
83d89b76
...
...
@@ -699,17 +699,28 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
// ONE-TO-ONE
if
(
$type
==
Doctrine_Relation
::
ONE_COMPOSITE
||
$type
==
Doctrine_Relation
::
ONE_AGGREGATE
)
{
// tree structure parent relation found
if
(
!
isset
(
$local
))
{
$local
=
$table
->
getIdentifier
();
}
$relation
=
new
Doctrine_Relation_LocalKey
(
$table
,
$foreign
,
$local
,
$type
,
$alias
);
}
else
{
// tree structure children relation found
if
(
!
isset
(
$local
))
{
$tmp
=
$table
->
getIdentifier
();
}
$local
=
$foreign
;
$foreign
=
$tmp
;
$relation
=
new
Doctrine_Relation_ForeignKey
(
$table
,
$foreign
,
$local
,
$type
,
$alias
);
}
}
elseif
(
$component
==
$name
||
(
$component
==
$alias
))
{
// && ($name == $this->options['name'] || in_array($name,$this->parents))
if
(
!
isset
(
$local
))
{
$local
=
$this
->
identifier
;
}
...
...
tests/TreeStructureTestCase.php
View file @
83d89b76
...
...
@@ -3,8 +3,12 @@ class TreeLeaf extends Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
);
$this
->
hasColumn
(
'parent_id'
,
'integer'
);
$this
->
hasOne
(
'TreeLeaf as Parent'
,
'TreeLeaf.parent_id'
,
'id'
);
}
public
function
setUp
()
{
$this
->
hasOne
(
'TreeLeaf as Parent'
,
'TreeLeaf.parent_id'
);
$this
->
hasMany
(
'TreeLeaf as Children'
,
'TreeLeaf.parent_id'
);
}
}
...
...
@@ -27,6 +31,18 @@ class Doctrine_TreeStructure_TestCase extends Doctrine_UnitTestCase
}
}
public
function
testLocalAndForeignKeysAreSetCorrectly
()
{
$component
=
new
TreeLeaf
();
$rel
=
$component
->
getTable
()
->
getRelation
(
'Parent'
);
$this
->
assertEqual
(
$rel
->
getLocal
(),
'parent_id'
);
$this
->
assertEqual
(
$rel
->
getForeign
(),
'id'
);
$rel
=
$component
->
getTable
()
->
getRelation
(
'Children'
);
$this
->
assertEqual
(
$rel
->
getLocal
(),
'id'
);
$this
->
assertEqual
(
$rel
->
getForeign
(),
'parent_id'
);
}
public
function
testTreeLeafRelationships
()
{
/* structure:
...
...
@@ -42,22 +58,26 @@ class Doctrine_TreeStructure_TestCase extends Doctrine_UnitTestCase
*/
$o1
=
new
TreeLeaf
();
$o1
->
Parent
=
null
;
$o1
->
name
=
'o1'
;
$o1
->
save
();
$o2
=
new
TreeLeaf
();
$o2
->
name
=
'o2'
;
$o2
->
Parent
=
$o1
;
$o2
->
save
();
$o3
=
new
TreeLeaf
();
$o3
->
name
=
'o3'
;
$o3
->
Parent
=
$o1
;
$o3
->
save
();
$o1
->
refresh
();
//
$o1->refresh();
$o4
=
new
TreeLeaf
();
$o4
->
name
=
'o4'
;
$o4
->
save
();
$o1
->
Children
;
$this
->
assertFalse
(
isset
(
$o1
->
Parent
));
$this
->
assertTrue
(
count
(
$o1
->
Children
)
==
2
);
$this
->
assertTrue
(
count
(
$o1
->
get
(
'Children'
))
==
2
);
...
...
tests/run.php
View file @
83d89b76
...
...
@@ -136,7 +136,6 @@ $test->addTestCase(new Doctrine_Collection_TestCase());
$test
->
addTestCase
(
new
Doctrine_Relation_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_Access_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_ManyToMany_TestCase
());
$test
->
addTestCase
(
new
Doctrine_TreeStructure_TestCase
());
// Datatypes
...
...
@@ -192,9 +191,10 @@ $test->addTestCase(new Doctrine_Query_AggregateValue_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_Select_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Expression_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Having_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_JoinCondition_TestCase
());
$test
->
addTestCase
(
new
Doctrine_TreeStructure_TestCase
());
// Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
...
...
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