Skip to content

[5.x]: Error in advanced element query "select" when adding column alias on custom field #15827

@danbrellis

Description

@danbrellis

What happened?

Description

When trying to do an advanced element query calling a custom field in the select statement, I get an SQL error if I give the custom field a column alias.

This works

{% set critters = craft.entries()
  .section('critters')
  .orderBy('title')
  .limit(null)
  .select(['title as t', 'scientificName'])
  .asArray()
  .all() %}

This doesn't work

{% set critters = craft.entries()
  .section('critters')
  .orderBy('title')
  .limit(null)
  .select(['title as t', 'scientificName as l'])
  .asArray()
  .all() %}

Note the as l for the scientificName custom field.

Expected behavior

An array of objects with keys t and l

Actual behavior

SQL error: Column not found: 1054 Unknown column 'scientificName' in 'field list'.

Craft CMS version

5.4.6

PHP version

8.3.10

Operating system and version

No response

Database type and version

mysql 8.0

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions