Skip to content

Add "Not Related To" to element queries#15496

Merged
brandonkelly merged 18 commits into5.4from
feature/cms-1306-add-not-related-to-functionality-for-element-queries
Aug 15, 2024
Merged

Add "Not Related To" to element queries#15496
brandonkelly merged 18 commits into5.4from
feature/cms-1306-add-not-related-to-functionality-for-element-queries

Conversation

@nfourtythree
Copy link
Copy Markdown
Contributor

@nfourtythree nfourtythree commented Aug 7, 2024

Description

Adds functionality to query elements that are not related to other elements.

This is possible with element queries in PHP, Twig and also via GraphQL.

A new "Not Related To" condition rule has also been added.

Some example twig code:

{# Where `entryA` and `entryB` are assumed to be valid entries retrieve from the system #}

{# Not related to `entryA` #}
{% set entries = craft.entries.notRelatedTo(entryA).all() %}

{# Related to `entryA` but not `entryB` #}
{% set entries = craft.entries.relatedTo(entryA).notRelatedTo(entryB).all() %}

{# Not related to `entryA` and `entryB` #}
{% set entries = craft.entries.notRelatedTo(['and', entryA, entryB]).all() %}

{# Not related to `entryA` and `entryB` using `andNotRelatedTo()` #}
{% set entries = craft.entries.notRelatedTo(entryA).andNotRelatedTo(entryB).all() %}

Example GraphQL:

{
  entries(notRelatedTo: ["123"]) {
    id
    title
    slug
  }
}

Related issues

@nfourtythree nfourtythree requested a review from a team August 7, 2024 12:27
@nfourtythree nfourtythree self-assigned this Aug 7, 2024
@linear
Copy link
Copy Markdown

linear Bot commented Aug 7, 2024

@brandonkelly brandonkelly changed the base branch from 5.x to 5.4 August 7, 2024 16:51
@brandonkelly brandonkelly merged commit b66ea39 into 5.4 Aug 15, 2024
@brandonkelly brandonkelly deleted the feature/cms-1306-add-not-related-to-functionality-for-element-queries branch August 15, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants