Skip to content

Add shortcut method for getting a modified query #4

@michaelrog

Description

@michaelrog

It'd be nice to have a shortcut syntax to get a Condition-modified query directly from the fieldtype value.

Current guidance:

{% set query = craft.entries.section('foo') %}
{% do myCondition.modifyQuery(query) %}
{% for entry in query.all() %}
  ...

Some potential implementations:

Option 1 — Get query from the Condition, passing in an ElementQuery

{% set query = myCondition.getModifiedQuery(craft.entries.section('foo')) %}
{% for entry in query.all() %}
  ...

Option 2 — Get query from the Condition, passing in element type (and optional query params)

{% set query = myCondition.find('entries').section('foo') %}
{% for entry in query.all() %}
  ...
{% set query = myCondition.find('entries', {section: 'foo'}) %}
{% for entry in query.all() %}
  ...

Option 3 — Apply Condition to query

{% set query = craft.entries.section('foo').applyCondition(myCondition) %}
{% for entry in query.all() %}
  ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions