Reputation: 3523
I got to table where one related to the other
TABLE A
uid
name
TABLE B
uid
name
rel_table_a
Now I would like:
// find all table A that is related to by table B
public function findAllTableAThatIsRelatedToByTableB() {
$query = $this->createQuery();
// what should this line be?
//$query->matching($query->count(tableB.rel_table_a = uid));
return $query->execute();
}
Is that possible or will the relation need to be created in the TCA for Table A first.
Upvotes: 0
Views: 387
Reputation: 4879
You can use related tables in the queries, but first you need to set up your TCA
and your models properly, otherwise extbase does not know how your tables are related.
As the query condition you could just check if the relation exists.
In your structure we can only do this query on the table B since your table A does not have a relation field, so in this example you will get all items from table B that have a table A element related.
$query->matching($query->greaterThan('rel_table_a.uid', 0));
If you have an 1:n relation from table A to table B, then you should use an inline field. This way you can do a query on the table A: https://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Inline/Index.html
PS: you can not use $query->count
inside a $query->matching
Upvotes: 2