【问题标题】:Query Contains for Entity Relationship 1:n查询包含实体关系 1:n
【发布时间】:2020-11-12 15:46:09
【问题描述】:

我想检查单词 $filterwords 是否出现在其中一个对象中并在我的小部件过滤器中过滤它们。

结构如下: 类博客有 n 个功能。并且功能有一个名称。

例如:

   Blog1
    -Feature1
     --Name "Fast"
    -Feature2
     --Name "Beautiful"
   Blog2
    -Feature1
     --Name "Fast"
   Blog3
    -Feature2
     --Name "Beautiful"

现在我想要所有具有“快速”属性的博客。

在 List.html 中,我实际上想这样调用我的过滤器:

<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.name">

但这是不可能的,因为特征是 n 个对象。 “关系匹配中使用的不支持或不存在的属性名称“name”。”

因此它只能这样工作:

<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features">

所以在我的小部件过滤器控制器中,我得到这样的属性:

    /**
     * @var QueryResultInterface
     */
    protected $objects;
    public function initializeAction()
    {
        $this->objects = $this->widgetConfiguration['objects'];
        $this->property = $this->widgetConfiguration['property'];
        $this->as = $this->widgetConfiguration['as'];
    }

    /**
     * @param string $filterword
     */
    public function indexAction(string $filterword = ""): void
    {
        $query = $this->objects->getQuery();
        $query->matching($query->contains($this->property, $filterword));
...

现在的问题是“包含”查询不起作用,因为他必须检查属性“功能”->“名称”。但它不会将“Feature.name”作为属性传递,而只会传递“特征”。您必须以某种方式告诉“包含”它应该检查“名称”。

【问题讨论】:

    标签: filter widget typo3 extbase fluid


    【解决方案1】:

    好的,我显然找到了问题。

    以下内容现在可以在 List.html 中使用:

    <example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.uid">
    

    在控制器中:

    $features = $this->featureRepository->getFeaturesByName($filterfeature);
            $query = $this->objects->getQuery();
            if(count($features) > 0) {
                $query->matching($query->in($this->property, $features));
            }
    

    但真正的问题显然是我连续连接了2个过滤器。

    <example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.uid">
        <example:widget.anotherfilter objects="{filteredblogs}" as="filteredmoreblogs" property="test.name">
    

    问题在于它只使用了第二个过滤器。如果我删除第二个过滤器,第一个过滤器会起作用。

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多