0
votes

I have a 1:n relation: An event can have many dates.

Now I would like to query the event repository and apply a filter on the childrecords "dates":

"Get all events which have dates where date.start > x"

The pure SQL query could be something like this:

SELECT tx_event_domain_model_event.*,tx_event_domain_model_date.*
FROM  tx_event_domain_model_event, tx_event_domain_model_date
WHERE tx_event_domain_model_date.event = tx_event_domain_model_event.uid
AND tx_event_domain_model_date.start > 1497960246

How can I do this query with the extbase query class in a repository?

1
Welcome to Stack Overflow, please show us what you have done so far, add some code and the results. Make sure to read How to create a Minimal, Complete, and Verifiable example - lordrhodos
Here is the reference for the extbase query : lbrmedia.net/codebase/Eintrag/extbase-query-methods - Ravi Sachaniya

1 Answers

3
votes

You can use the Extbase Query Object for getting just the events with certain dates.

I assume you have a field 'date' in your event model, that keeps track of the added events.

It haven't tested it, but your function would look something like this:

// assuming your repository is "eventRepository"
$startDate = 1497960246;
$query = $this->eventRepository->createQuery();
$query->matching($query->greaterThan('date.start', $startDate));
$events = $query->execute();

You can read more about custom database queries with the extbase query object here in the typo3 docs