I have been trying to get some campaigns from a ta...
# orm-help
j
I have been trying to get some campaigns from a table based on some conditions from the relation table.
Copy code
await prisma.campaigns.findMany({
        select:{
            url:true
        },
        where: {
            status:{
                eq: 1
            },
            AND: {
                {
                    // some conditions
                },
                {
                    // [BUG] relation based condition. 
                    OR: [
                        {
                            offer_devices: undefined
                        },
                        {
                            // condition based on offer devices.
                        }
                    ]
                },
            }
        }
    })
In this, if the offer_devices relation is null, then the condition is not working. I have tried to comment on the relation condition and it works. Looks like this condition has the issue.
Copy code
{
	offer_devices: undefined
}
r
What is the relation of campaigns and offer_devices in your schema?
Also if you want to check for nullability then you need to use:
Copy code
offer_devices: null
Instead of
undefined
as both have different meanings and
null
is what you want to use for relations.
j
(campaigns) one to many relation (devices).
I have tried to use the null. got this error.
Copy code
Argument offer_devices for where.AND.2.OR.0.offer_devices must not be null. Please use undefined instead.
Copy code
{
            offer_devices: null
                           ~~~~
}
r
As itโ€™s a 1-many relation, you need to use this:
Copy code
await prisma.campaign.findMany({
    where: {
      status: 1,
      AND: [{ OR: [{ offer_devices: { none: {} } }] }],
    },
  })
This will find campaigns with no offer_devices.
๐Ÿ‘ 1
j
Got it.
๐Ÿ‘ 1