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 "Not Related To" to element queries #15496

Conversation

nfourtythree
Copy link
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
Copy link

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
5 checks passed
@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