Is it possible to eagerLoad fields in categories?

I have this code;

{% set markets = craft.categories.group({
  section: 'markets',
  with: ['bannerImage']
}) %}

which for some reason is throwing an error;

mb_convert_case() expects parameter 1 to be string, array given

Is this a bug or something bad in my code? Removing the with call and it renders fine.


This is basically just a syntax error. What you are doing is: searching for entries in the group section: 'markets', with: ['bannerImage'] but what you want is searching for categories in the group markets with the field bannerImage

{% set markets = craft.categories.group('markets').with(['bannerImage']).all() %}

The group parameter in your CategoryQuery defined which group(s) you want to select. The with parameter your eager-loading elements. Btw: Categories have no section property


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.