Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFieldValue() not returning eager-loaded data #10047

Closed
mattsbanner opened this issue Nov 2, 2021 · 1 comment
Closed

getFieldValue() not returning eager-loaded data #10047

mattsbanner opened this issue Nov 2, 2021 · 1 comment
Labels

Comments

@mattsbanner
Copy link

Description

I'm not completely sure if this is intended behaviour or not but when using with() on an Entry query to eager-load the relations getFieldValue() returns the query, not the eager-loaded results.

This makes it difficult to get the results of all fields with getFieldValues().

If this is intended, is there a way to get all field values including eager-loaded data, without having to use something like $entry->fields() to fetch the values individually with $entry->{$fieldName}?

Steps to reproduce

When running this code

$entry = Entry::find()
    ->with([
        'relatedCategories',
        'contentBuilder'
    ])
    ->section('pages')
    ->one();

$entry->relatedCategories and $entry->contentBuilder return the expected eager-loaded results.

[
    craft\elements\Category,
    craft\elements\Category
]
[
    craft\elements\MatrixBlock
]

However, $entry->getFieldValues() will return

  "relatedCategories" => craft\elements\db\CategoryQuery
  "contentBuilder" => craft\elements\db\MatrixBlockQuery

Additional info

  • Craft version: 3.7.19
  • PHP version: 7.4
  • Database driver & version: MySQL 5.7
  • Plugins & versions: None, tested on base install.
@brandonkelly
Copy link
Member

Agree that’s a little awkward. The change could have some unexpected behavior though, so I just changed in for Craft 4 rather than the next 3.x release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants