TYPO3 Extbase:过滤1:N关系 [英] TYPO3 Extbase: Filtering a 1:N relation
问题描述
我有一个1:n关系:一个事件可以有多个日期.
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":
获取所有日期为date.start> x的事件"
"Get all events which have dates where date.start > x"
纯SQL查询可能是这样的:
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
如何使用存储库中的extbase查询类执行此查询?
How can I do this query with the extbase query class in a repository?
推荐答案
您可以使用Extbase查询对象来仅获取具有特定日期的事件.
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
这篇关于TYPO3 Extbase:过滤1:N关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!