Project

General

Profile

Actions

Bug #27057

closed

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

Added by Björn Steinbrink over 13 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Must have
Category:
Extbase
Target version:
Start date:
2011-05-26
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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 ...


Related issues 3 (0 open3 closed)

Related to TYPO3 Core - Bug #62151: addUnionStatement does not handle multiple fields with same related tableClosed2014-10-10

Actions
Related to TYPO3 Core - Bug #58511: addUnionStatement does not respect MM_match_fieldsClosed2014-05-05

Actions
Has duplicate TYPO3 Core - Feature #55959: Joins on SubClassesClosed2014-02-13

Actions
Actions #1

Updated by Alexander Schnitzler about 12 years ago

  • Status changed from New to Accepted
  • Assignee set to Alexander Schnitzler
  • Target version set to 1843

Can be reproduced, try to fix this.

Actions #2

Updated by Gerrit Code Review about 12 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16535

Actions #3

Updated by Gerrit Code Review about 12 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16535

Actions #4

Updated by Gerrit Code Review about 12 years ago

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16537

Actions #5

Updated by Alexander Schnitzler about 12 years ago

  • Target version changed from 1843 to Extbase 6.0
Actions #6

Updated by Anonymous about 12 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Applied in changeset commit:36203cc17d46ac07088ddd17f21440c00a46a969.

Actions #7

Updated by Mathias Brodala over 11 years ago

This error still appears in the current stable release (6.1.1) with this simple setup:

Domain model

namespace TEST\RelationQueryTest\Domain\Model;
class Element extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
  /**
   * @var \string
   * @validate NotEmpty
   */
  protected $title;
  /**
   * @var \TEST\RelationQueryTest\Domain\Model\Element
   */
  protected $relatedElement;
  /* getters/setters ommitted */
}

Domain repository

namespace TEST\RelationQueryTest\Domain\Repository;
class ElementRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
  /**
   * @param \string $title
   * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array
   */
  public function findByRelatedElementTitle($title) {
    $query = $this->createQuery();
    return $query->matching($query->equals('relatedElement.title', $title))->execute();
  }
}

TCA configuration

$TCA['tx_relationquerytest_domain_model_element'] = array(
  /* ctrl, interface, types omitted */
  'columns' => array(
    'title' => array(
      'exclude' => 0,
      'label' => 'Title',
      'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval' => 'trim,required'
      ),
    ),
    'related_element' => array(
      'exclude' => 0,
      'label' => 'Related element',
      'config' => array(
        'type' => 'inline',
        'foreign_table' => 'tx_relationquerytest_domain_model_element',
        'minitems' => 0,
        'maxitems' => 1,
        'appearance' => array(
          'collapseAll' => 0,
          'levelLinksPosition' => 'top',
          'showSynchronizationLink' => 1,
          'showPossibleLocalizationRecords' => 1,
          'showAllLocalizationLink' => 1
        ),
      ),
    ),
  ),
);

The error again:

#1247602160: Not unique table/alias: 'tx_relationquerytest_domain_model_element':
SELECT COUNT(DISTINCT tx_relationquerytest_domain_model_element.uid)
FROM tx_relationquerytest_domain_model_element
LEFT JOIN tx_relationquerytest_domain_model_element
ON tx_relationquerytest_domain_model_element.related_element=tx_relationquerytest_domain_model_element.uid
WHERE tx_relationquerytest_domain_model_element.title = 'A'
AND tx_relationquerytest_domain_model_element.deleted=0
AND tx_relationquerytest_domain_model_element.t3ver_state<=0
AND tx_relationquerytest_domain_model_element.pid<>-1
AND tx_relationquerytest_domain_model_element.hidden=0
AND tx_relationquerytest_domain_model_element.starttime<=1374245400
AND (tx_relationquerytest_domain_model_element.endtime=0
  OR tx_relationquerytest_domain_model_element.endtime>1374245400
)
AND (tx_relationquerytest_domain_model_element.sys_language_uid IN (0,-1))
AND tx_relationquerytest_domain_model_element.pid IN (7)

There is no passthrough in the TCA configuration anywhere as mentioned in the commit message. How can one fix this error?

Actions #8

Updated by Gerrit Code Review about 10 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #9

Updated by Alexander Stehlik about 10 years ago

I stumbled over the same issue and as far as I can see the patch from Alex did not resolve it.

This can be easily reproduces with a functional test (see first patch in the review system).

@Mathias: does the patch from http://review.typo3.org/33956 resolve the issue for you?

Actions #10

Updated by Gerrit Code Review about 10 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #11

Updated by Gerrit Code Review about 10 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #12

Updated by Alexander Opitz about 10 years ago

  • Project changed from 534 to TYPO3 Core
  • Category changed from Extbase: Generic Persistence to Extbase
  • Target version changed from Extbase 6.0 to 7.0
  • TYPO3 Version set to 6.2
  • Is Regression set to No
Actions #13

Updated by Gerrit Code Review almost 10 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #14

Updated by Gerrit Code Review almost 10 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #15

Updated by Mathias Schreiber almost 10 years ago

  • Target version changed from 7.0 to 7.1 (Cleanup)
Actions #16

Updated by Gerrit Code Review over 9 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #17

Updated by Benni Mack over 9 years ago

  • Target version changed from 7.1 (Cleanup) to 7.4 (Backend)
Actions #18

Updated by Susanne Moog over 9 years ago

  • Target version changed from 7.4 (Backend) to 7.5
Actions #19

Updated by Gerrit Code Review about 9 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #20

Updated by Benni Mack about 9 years ago

  • Target version deleted (7.5)
Actions #21

Updated by Gerrit Code Review about 9 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #22

Updated by Gerrit Code Review about 9 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #23

Updated by Stephan Großberndt about 9 years ago

  • Target version set to 7 LTS
  • TYPO3 Version changed from 6.2 to 7
Actions #24

Updated by Gerrit Code Review about 9 years ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #25

Updated by Gerrit Code Review about 9 years ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33956

Actions #26

Updated by Alexander Stehlik about 9 years ago

  • Status changed from Under Review to Resolved
Actions #27

Updated by Riccardo De Contardi about 7 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF