【问题标题】:Defining Custom Parameters on Eager-Loaded Elements在预加载元素上定义自定义参数
【发布时间】:2021-12-27 01:02:32
【问题描述】:

我正在尝试完成一个预先加载的查询,该查询将拉入条目上的所有相关字段,即使它们被禁用。

我在文档中将此用作参考: https://craftcms.com/docs/3.x/dev/eager-loading-elements.html#defining-custom-parameters-on-eager-loaded-elements

这是我写的:

$facility = Entry::find()
            ->id($entryId)
            ->with([
                ['services', {status: null}],
                ['conditions', {status: null}]
            ])
            ->status(null)
            ->one();

但我不断收到语法错误

syntax error, unexpected '{', expecting ']'

有谁知道我做错了什么以及为什么?蒂亚!

【问题讨论】:

    标签: php eager-loading nested-queries craftcms


    【解决方案1】:

    语法咒语问题。我试图在 PHP 模块中编写 Craft 查询。 PHP 不想看到卷曲的 bois。下面的更正代码有效!

    $facility = Entry::find()
                ->id($entryId)
                ->with([
                    ['services', ['status' => null]],
                    ['conditions', ['status' => null]],
                ])
                ->status(null)
                ->one();
    

    希望这对将来的某人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多