Extbase query to compare two fields in same table

為{幸葍}努か 提交于 2019-12-10 15:57:46

问题


Is it possible to compare two database fields in the query api? For example I want compare the fields tstamp and crdate like:

SELECT * FROM tt_content WHERE tstamp > crdate;

In the query api I could not found a solution. To get all records and compare the fields in a loop is not a performed way, because this could be over 2 million records (in my real case).

Thanks for your help.


回答1:


The only way I can think of (and that the query builder supports) is to directly supply the statement. It'll look like this:

$query = $contentElementRepository->createQuery();
$query->statement('SELECT * FROM tt_content WHERE tstamp > crdate');
$matchingContentElements = $query->execute();

This probably breaks the database abstraction layer, so use it with caution. statement() has a second parameter where you can put parameters, in case you need some user input in the query.

Maybe there is another way to do this which I don't know, I'd be really interested in it myself.



来源:https://stackoverflow.com/questions/39497503/extbase-query-to-compare-two-fields-in-same-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!