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

fix(drizzle): support equals polymorphic querying with object notation #8316

Open
wants to merge 5 commits into
base: beta
Choose a base branch
from

Conversation

r1tsuu
Copy link
Collaborator

@r1tsuu r1tsuu commented Sep 19, 2024

Previously, this wasn't valid in Postgres / SQLite:

const res = await payload.find({
  collection: 'polymorphic-relationships',
  where: {
    polymorphic: {
      equals: {
        relationTo: 'movies',
        value: movie.id,
      },
    },
  },
})

Now it works and actually in more performant way than this:

const res = await payload.find({
  collection: 'polymorphic-relationships',
  where: {
    and: [
      {
        'polymorphic.relationTo': {
          equals: 'movies',
        },
      },
      {
        'polymorphic.value': {
          equals: 'movies',
        },
      },
    ],
  },
})

Why? Because with the object notation, the output SQL is: movies_id = 1 - checks exactly 1 column in the *_rels table, while with the separate query by relationTo and value we need to check against each possible relationship collection with OR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant