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
9bd341d7
Commit
9bd341d7
authored
Aug 25, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doctrine_Record::countRelated() added
parent
5b0858cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
8 deletions
+42
-8
Query.php
Doctrine/Query.php
+2
-2
Record.php
Doctrine/Record.php
+9
-4
QueryTestCase.php
tests/QueryTestCase.php
+12
-2
RecordTestCase.php
tests/RecordTestCase.php
+16
-0
classes.php
tests/classes.php
+3
-0
No files found.
Doctrine/Query.php
View file @
9bd341d7
...
...
@@ -713,7 +713,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if
(
!
isset
(
$this
->
tables
[
$tableName
]))
{
$this
->
tables
[
$tableName
]
=
$table
;
if
(
$loadFields
&&
!
$this
->
aggregate
)
{
if
(
$loadFields
)
{
$this
->
parseFields
(
$fullname
,
$tableName
,
$e2
,
$currPath
);
}
}
...
...
@@ -767,7 +767,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
}
if
(
!
$this
->
aggregate
)
$this
->
loadFields
(
$table
,
$fetchmode
,
$fields
,
$currPath
);
$this
->
loadFields
(
$table
,
$fetchmode
,
$fields
,
$currPath
);
}
public
function
parseAggregateFunction
(
$func
,
$reference
)
{
$pos
=
strpos
(
$func
,
"("
);
...
...
Doctrine/Record.php
View file @
9bd341d7
...
...
@@ -1262,12 +1262,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
/**
* countRelated
*
* @return integer
*/
public
function
countRelated
(
$name
)
{
$rel
=
$this
->
table
->
getForeignKey
(
$name
);
$componentName
=
$rel
->
getTable
()
->
getTableName
();
return
$rel
->
getCountFor
(
$this
);
$rel
=
$this
->
table
->
getForeignKey
(
$name
);
$componentName
=
$rel
->
getTable
()
->
getComponentName
();
$alias
=
$rel
->
getTable
()
->
getAlias
(
get_class
(
$this
));
$query
=
new
Doctrine_Query
();
$query
->
from
(
$componentName
.
'('
.
'COUNT(1)'
.
')'
)
->
where
(
$componentName
.
'.'
.
$alias
.
'.'
.
$this
->
getTable
()
->
getIdentifier
()
.
' = ?'
);
$array
=
$query
->
execute
(
array
(
$this
->
getIncremented
()));
return
$array
[
0
][
'COUNT(1)'
];
}
/**
* merge
...
...
tests/QueryTestCase.php
View file @
9bd341d7
...
...
@@ -25,6 +25,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
}
public
function
testSelectingAggregateValues
()
{
$q
=
new
Doctrine_Query
();
$q
->
from
(
"User(COUNT(1), MAX(name))"
);
$array
=
$q
->
execute
();
...
...
@@ -34,7 +35,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$q
=
new
Doctrine_Query
();
$q
->
from
(
"Phonenumber(COUNT(1))"
);
$array
=
$q
->
execute
();
$this
->
assertTrue
(
is_array
(
$array
));
$this
->
assertEqual
(
$array
,
array
(
array
(
'COUNT(1)'
=>
'15'
)));
...
...
@@ -52,10 +53,20 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$q
->
from
(
"User(MAX(id)).Email(MIN(address))"
);
$array
=
$q
->
execute
();
$this
->
assertTrue
(
is_array
(
$array
));
$this
->
assertEqual
(
$array
[
0
][
'MAX(entity.id)'
],
11
);
$this
->
assertEqual
(
$array
[
0
][
'MIN(email.address)'
],
'arnold@example.com'
);
$q
=
new
Doctrine_Query
();
$q
->
from
(
"User(MAX(id)).Email(MIN(address)), User.Phonenumber(COUNT(1))"
);
$array
=
$q
->
execute
();
$this
->
assertTrue
(
is_array
(
$array
));
$this
->
assertEqual
(
$array
[
0
][
'MAX(entity.id)'
],
11
);
$this
->
assertEqual
(
$array
[
0
][
'MIN(email.address)'
],
'arnold@example.com'
);
$this
->
assertEqual
(
$array
[
0
][
'COUNT(1)'
],
14
);
}
public
function
testMultipleFetching
()
{
$count
=
$this
->
dbh
->
count
();
$this
->
connection
->
getTable
(
'User'
)
->
clear
();
...
...
@@ -1213,6 +1224,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max']));
}
}
?>
tests/RecordTestCase.php
View file @
9bd341d7
...
...
@@ -93,6 +93,22 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$coll
->
count
(),
1
);
}
public
function
testCountRelated
()
{
$user
=
$this
->
connection
->
getTable
(
'Entity'
)
->
find
(
5
);
$c
=
$user
->
countRelated
(
'Phonenumber'
);
$this
->
assertEqual
(
$c
,
3
);
$user
=
$this
->
connection
->
getTable
(
'Entity'
)
->
find
(
7
);
$c
=
$user
->
countRelated
(
'Phonenumber'
);
$this
->
assertEqual
(
$c
,
1
);
$user
=
$this
->
connection
->
getTable
(
'Entity'
)
->
find
(
8
);
$c
=
$user
->
countRelated
(
'Phonenumber'
);
$this
->
assertEqual
(
$c
,
3
);
}
public
function
testUpdatingWithNullValue
()
{
$user
=
$this
->
connection
->
getTable
(
'User'
)
->
find
(
5
);
$user
->
name
=
null
;
...
...
tests/classes.php
View file @
9bd341d7
...
...
@@ -97,6 +97,9 @@ class Phonenumber extends Doctrine_Record {
$this
->
hasColumn
(
"phonenumber"
,
"string"
,
20
);
$this
->
hasColumn
(
"entity_id"
,
"integer"
);
}
public
function
setUp
()
{
$this
->
hasOne
(
"Entity"
,
"Phonenumber.entity_id"
);
}
}
class
Element
extends
Doctrine_Record
{
...
...
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