payload icon indicating copy to clipboard operation
payload copied to clipboard

fix(db-mongodb): querying by localized polymorphic relationships using objects

Open r1tsuu opened this issue 2 months ago • 0 comments

Previously, queries like this didn't work:

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

This was due to the incorrectly passed path to MongoDB without .{locale} suffix. Additionally, to MongoDB now we send:

{
  polymorphic: {
    $eq: {
      relationTo: 'movies',
      value: 'some-id',
    },
  },
}

Instead of:

{
  and: [
    {
      'polymorphic.relationTo': {
        $eq: 'movies ',
      },
    },
    {
      'polymorphic.value': {
        $eq: 'some-id ',
      },
    },
  ],
}

To match the exact value. This is essential when we do querying by relationships with hasMany: true and custom IDs that can be repeated.

r1tsuu avatar Dec 18 '24 06:12 r1tsuu