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

Cannot get model with null condition #228

Open
Karibash opened this issue Jun 29, 2022 · 2 comments
Open

Cannot get model with null condition #228

Karibash opened this issue Jun 29, 2022 · 2 comments

Comments

@Karibash
Copy link

Current behavior

It is not possible to get a model for which a specific property is null.

const db = factory({
  user: {
    id: primaryKey(Number),
    deletedAt: nullable(Number),
  },
});

db.user.create({
  id: 1,
  deletedAt: null
});

db.user.create({
  id: 2,
  deletedAt: new Date().getTime()
});

const deletedUsers = db.user.findMany({ where: { deletedAt: { equals: null } } });
console.log(deletedUsers);
// -> []

Minimum reproduction code

https://codesandbox.io/s/inspiring-fog-wesv28?file=/index.js

Expected behavior

It seems that the compileQuery function is returning false if the property value is null.
I think it needs to flow to subsequent processing even if the property value is null.

// If an entity doesn't have any value for the property
// is being queried for, treat it as non-matching.
if (actualValue == null) {
return false
}

@kettanaito
Copy link
Member

Hey, @Karibash. Thanks for sharing this!

We are aware of this limitation and working on it in #187. So far, there's only an integration test that confirm the issue is there.

I can't promise anything as to when this is going to be resolved though. As one of my countless endeavours, I'm also rewriting how Data works from scratch to account for some fundamental shortcomings its current design has, and enable more features like querying by null.

That being said, I'm unlikely to prioritize this issue any time soon. Anybody is welcome to tackle this, taking the referenced pull request and its tests as a starting point. If not, expect this to be fixed once the rewrite is done. Thanks.

@jckw
Copy link

jckw commented May 2, 2024

+1

This would be neat to have!

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

No branches or pull requests

3 participants