Issue Bug Closed

#27057Can't query on properties of child objects of the same class

Björn Steinbrink 05/26/11, 17:53 updated 10/21/17, 17:45

Description

Given a domain model that has a connection to another object of the same class like this:

class Tx_Whatever_Domain_Model_Foo {
  /**
   * @var Tx_Whatever_Domain_Model_Foo
   */
   protected $parent;
}

And given this repository method:

class Tx_Whatever_Domain_Repository_FooRepository {
  public findByParentTitle($title) {
    $query = $this->createQuery();
    return $query->matching($query->equals('parent.title', $title))->execute();
  }
}

Running $repository->findByParentTitle('test');, extbase generates invalid SQL and crashes.

An error occured. Exception thrown:
Tx_Extbase_Persistence_Storage_Exception_SqlError
Error message: Not unique table/alias: 'tx_whatever_domain_model_foo':

SELECT DISTINCT tx_whatever_domain_model_foo.*
FROM tx_whatever_domain_model_foo
LEFT JOIN tx_whatever_domain_model_foo ON tx_whatever_domain_model_foo.parent=tx_whatever_domain_model_foo.uid
WHERE tx_whatever_domain_model_foo.parent = 'test' AND ...

Reviews 1