Skip to content

Commit

Permalink
can retrieve descendants of given class
Browse files Browse the repository at this point in the history
  • Loading branch information
juzna committed Apr 6, 2012
1 parent 052d2a9 commit bec5a28
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function childCount($node = null, $direct = false)
* @param string $sortByField - field name to sort by
* @param string $direction - sort direction : "ASC" or "DESC"
* @throws InvalidArgumentException - if input is not valid
* @return Doctrine\ORM\QueryBuilder
* @return \Doctrine\ORM\QueryBuilder
*/
public function childrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC')
{
Expand All @@ -239,7 +239,9 @@ public function childrenQueryBuilder($node = null, $direct = false, $sortByField
->from($config['useObjectClass'], 'node')
;
if ($node !== null) {
if ($node instanceof $meta->name) {
// WTF? Seriously? Why you do this to me?
// if ($node instanceof $meta->name) {
// FIXME: should check if has common ancestor which is a base tree node
$wrapped = new EntityWrapper($node, $this->_em);
if (!$wrapped->hasValidIdentifier()) {
throw new InvalidArgumentException("Node is not managed by UnitOfWork");
Expand All @@ -261,9 +263,9 @@ public function childrenQueryBuilder($node = null, $direct = false, $sortByField
$rootId = $wrapped->getPropertyValue($config['root']);
$qb->andWhere("node.{$config['root']} = {$rootId}");
}
} else {
throw new \InvalidArgumentException("Node is not related to this repository");
}
// } else {
// throw new \InvalidArgumentException("Node is not related to this repository");
// }
} else {
if ($direct) {
$qb->where('node.' . $config['parent'] . ' IS NULL');
Expand Down

0 comments on commit bec5a28

Please sign in to comment.