简体   繁体   English

TYPO3 Extbase:使用setEnableFieldsToBeIgnored的查询生成器

[英]TYPO3 Extbase: Query Builder using setEnableFieldsToBeIgnored

TL;DR: How can I use getQuerySettings()->setEnableFieldsToBeIgnored() to work on a relation instead of the "base" table? TL; DR:如何使用getQuerySettings()-> setEnableFieldsToBeIgnored()处理关系而不是“基本”表? Using array('fe_users.disable') does not work. 使用array('fe_users.disable')不起作用。

I have a DB model called "parks" which has three fields: "leader", "administrator" and "partner". 我有一个名为“ parks”的数据库模型,该模型具有三个字段:“ leader”,“ administrator”和“ partner”。 All are optional joins on the fe_user table. 所有这些都是fe_user表上的可选联接。

Now I want to create a repository method that fetches a park where a given fe_user is either leader, administrator or partner. 现在,我想创建一个存储库方法来获取一个给定的fe_user是领导者,管理员或伙伴的公园。 This works like: 运作方式如下:

$query = $this->createQuery();
$where[] = $query->equals('parkusersLeader.uid', $userUid);
$where[] = $query->equals('parkusersAdministrators.uid', $userUid);
$where[] = $query->equals('parkusersPartner.uid', $userUid);
$query->matching($query->logicalOr($where));

This actually creates a SQL query where a JOIN is made for each of the MM-tables to the "fe_users" table, but a WHERE statement is enabled for each of the fe_users table joins, adding a "fe_users.disable=0" to it. 实际上,这会创建一个SQL查询,其中会为“ fe_users”表的每个MM表创建一个JOIN,但是会为每个fe_users表的联接启用WHERE语句,并向其中添加“ fe_users.disable = 0” 。 So as soon as any park has multiple users assigned and one of the users assigned therein is disabled, the whole query will fail and not return the park. 因此,一旦任何公园分配了多个用户并且其中分配的用户之一被禁用,整个查询将失败并且不返回公园。

So how can I use the setEnableFieldsToBeIgnored() method to not make extbase append the "disable" clause for a fe_user join at this place? 那么,如何在这里不使用setEnableFieldsToBeIgnored()方法不让extbase为fe_user连接添加“禁用”子句呢? I tried: 我试过了:

$query->getQuerySettings()->setEnableFieldsToBeIgnored(array('parkusersLeader.disable', 'parkusersLeader.disabled', 'fe_users.disabled', 'fe_users.disable', 'disabled', 'starttime'));

None of those seem to change the SQL query at all. 这些似乎都没有改变SQL查询。

You need to enable the option to ignore disable fields explicitely. 您需要启用该选项以显式忽略禁用字段。

Have you tried setting the following for your query 您是否尝试过为查询设置以下内容

$query->getQuerySettings()->setIgnoreEnableFields(true);
$query->getQuerySettings()->setEnableFieldsToBeIgnored(['disable']);

(This should ignore the disabled attribute in all records. It might be possible to be more specific in the field definition - as per your example. You could also set those globally for the repository.) (这应该忽略所有记录中的disabled属性。根据您的示例,在字段定义中可能更具体。也可以为存储库全局设置这些属性。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM