1

I'm having trouble to get Eager Loading to work with an entries field that can select entries from another site in a multi-site setup.

We're using a Matrix content-builder setup. Different kinds of blocks for text, images, etc. That works well.

We also have a Widget block type that consists of one entries field. You can select an entry from a Widget section. That section has multiple entry types for "special content blocks". In one of these entry types we have another Matrix field. One of the blocks has an entries field were you can select from other sites.

When not eager loading, it all works. On the Widget-entry-type template I can do entry.entriesField.site('*').unique().one() to get the related entry from another site.

When I select only entries from the same site, it works. But when I also select entries from another site, I get empty arrays and errors.

I have tried these notations:

{% set content = entry.matrixField
  .site('*')
  .unique()
  .with([
    'simpleBlockType:assetsField',
    'widgetBlockType:entriesField.matrixField:entriesField,
  )]
  .all()
%}

And

{% set content = entry.matrixField
  .with([
    'simpleBlockType:assetsField',
    ['widgetBlockType:entriesField.matrixField:entriesField', { site: '*', unique: true }],
  )]
  .all()
%}

On the Widget-entry-type template I've tried:

{% set relatedEntry = entry.matrixField.entriesField[0] ?? null %}
{{ relatedEntry.title }}

Which results in Key "0" in object with ArrayAccess of class "craft\elements\db\EntryQuery" does not exist.

  • Craft CMS 3.5.17.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.