#✅ Filter exactly match (something like _in and _eq combined) many to many relation

28 messages · Page 1 of 1 (latest)

sullen igloo
#

Hello, we use Directus and we love it but I think it missing some basic filters

on of them was _ineq which we need to filter some conversation before create new conversation if smaller is already exists then return it without create new conversation

anyway, I tried _eq and _in and they do filter for array if any of them contain the string then return it

// notice payload.to is array contain the following
// [{
//   directus_users_id: {
//     id: "user id"
//   }
// }]

if (!payload.broadcast && payload?.to?.length) {
  let conversation = await directus.items("conversations").readByQuery({
    filter: {
      _or: [
        {
          broadcast: {
            _eq: false
          },
          from: {
            _eq: user.id
          },
          to: {
            // filter many to many exactly by id
            directus_users_id: {
              id: {
                _in: payload.to.map(({ directus_users_id: { id } }) => id)
              },
            }
          }
        },
      ]
    },
    limit: 1
  });

  if(conversation.data.length) {
    return conversation.data[0];
  }
}
drowsy galeBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

pallid plinth
#

What is the question? 🤔 does the filter not work ass expected, if so how?

sullen igloo
#

@pallid plinth yes, it not working as excepted because it filter any for both _eq and _in

#

we need something to do it exactly

pallid plinth
#

that is beacuse you're doing them in _or sounds like you want to do _and instead

sullen igloo
#

maybe add new filter bypass like _some and _none with name _exactly

#

@pallid plinth I tried them too, they search to any always

#

also I didn't write other items of _or filters

pallid plinth
#

Can you try explaining what exactly it is you want to happen here? i doubt a new operator is needed to make it happen 🙂

sullen igloo
#

if you I can call you maybe I can explain and show you

pallid plinth
#

No thanks, please try writing it out

sullen igloo
#

I will try 🙂

#

@pallid plinth if you can see I tried to filter with _in and _eq and both of them return items that has any of directus_users

#

I found that in the document mention that it default to _some for many-to-any relations

pallid plinth
#

Yeah that is correct both these filters do the same because you're filtering any conversation that has a user with that ID

#

isOneOf with one item will mostly behave the same as equals

#

but what is it you want to receive here?

sullen igloo
pallid plinth
sullen igloo
#

there second issue will appear that we cannot sort many-to-any relations

pallid plinth
pallid plinth
sullen igloo
#

@pallid plinth thank you, that work, I will try to found the issue of count later

drowsy galeBOT
#

✅ Filter exactly match (something like _in and _eq combined) many to many relation