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

Add shortcut method for getting a modified query #4

Open
michaelrog opened this issue Jul 26, 2023 · 1 comment
Open

Add shortcut method for getting a modified query #4

michaelrog opened this issue Jul 26, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@michaelrog
Copy link
Member

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() %}
  ...
@michaelrog michaelrog added enhancement New feature or request help wanted Extra attention is needed labels Jul 26, 2023
@piotrpog
Copy link

Or we could hust have method like getQuery() - it would just output query generated by condition field. And later you would be able to add your own rules there in the template by chaining other element query methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants