Cms: Use distinct() on element queries

Created on 8 Feb 2018  路  1Comment  路  Source: craftcms/cms

Description

It looks like it鈥檚 currently not possible to use the distinct() method on element queries. I wonder if I鈥檓 approaching this the wrong way or if it鈥檚 simply not possible right now.

{% set plainTexts = craft.entries()
    .select('field_plainText')
    .distinct()
    .column() %} 

Yii docs:
http://www.yiiframework.com/doc-2.0/yii-db-query.html#distinct()-detail

Additional info

  • Craft version: 3.0.0-RC9

Most helpful comment

Added distinct() support for RC10. Note that you will most likely need to clear out the default orderBy param as well:

{% set plainTexts = craft.entries()
    .select('field_plainText')
    .distinct()
    .orderBy(null)
    .column() %}

>All comments

Added distinct() support for RC10. Note that you will most likely need to clear out the default orderBy param as well:

{% set plainTexts = craft.entries()
    .select('field_plainText')
    .distinct()
    .orderBy(null)
    .column() %}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccombs picture mccombs  路  3Comments

bitboxfw picture bitboxfw  路  3Comments

michel-o picture michel-o  路  3Comments

lukebailey picture lukebailey  路  3Comments

davist11 picture davist11  路  3Comments