dora
dora

Reputation: 1344

Inner Join in TYPO3 Extbase

I have two tables TableA and TableB. These have to be joined together on the condition TableA.Pid = TableB.Uid.

The domain objects of the tables are created while building an extension using extension builder.

How do I achieve this in TYPO3?

Upvotes: 2

Views: 961

Answers (1)

Mateng
Mateng

Reputation: 3734

Short answer: For the field pid, you can't do that out of the blue. pid is a reserved identifier for the pages table and cannot be freely used. Also, in an MVC scheme, the concept of INNER JOIN connections is not implemented as such. Unfortunately, IMHO. It was so easy to mess around in the old days ;).

Here comes a more general approach for those who are new to this:
Assuming, your table A is named parent and table B is named child.

  • You can set the relations in the extension builder within the domain model dialogue. Create two domain models: Parent and Child.
  • Connect them by creating a relation parentrecord in the Child domain model which links to the model Parent.
  • Make sure to create both as aggregate root

enter image description here

The parentrecord relation will be defined in your model my_ext/Classes/Domain/Model/Child.php.
The @var annotation links it to the parent domain model:

/**
 * parentrecord
 *
 * @var \TYPO3\MyExt\Domain\Model\Parent
 */
protected $parentrecord;

All children of a parent record (e.g., parent uid = 42) can then be retrieved from your controller like that:

$this->childRepository->findByParentrecord(42);

This is an abbreviated answer. Note that your custom Extbase code might not work out of the box, but don't get frustrated - It will work eventually. As for the pid thing, I will try to help you on your related other question.

Upvotes: 3

Related Questions