Search code examples
typo3one-to-many

Typo3 DatabaseQueryProcessor one-to-many relation


I want to join a table with a one-to-many relation in the DatabaseQueryProcessor. table1.images contains a comma separated list of image-uids from table2. e.g. 1,2,3. In this example I would expect to get all 3 images as a result.

I tried:

dataProcessing {
    10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
    10 {
        table = table1
        join = table2 on table1.images in (table2.uid)

        as = someValue
    }
}

But this only gives me the first image "1" but not the other two images.

How can a one-to-many relation be reflected in the DatabaseQueryProcessor?

I figured it out:

join = table2 ON table1.images like concat('%', table2.uid , '%') and

join = table2 ON find_in_set(table2.uid, table1.images) does work


Solution

  • You are trying to check equality ("=") between a list and a single value. I wonder that you are getting a valid result at all and not an exception/error...

    Have a look at SQL function for lists:

    IN():

    join = table2 on table2.uid IN(table1.images)