prismock icon indicating copy to clipboard operation
prismock copied to clipboard

Unique ID enforcement?

Open artificial-aidan opened this issue 1 year ago • 5 comments

I'm using @@id to set a field as the ID, but prismock lets me create multiple objects with the same ID. Is this expected? I couldn't find anywhere in the code that would enforce that.

artificial-aidan avatar Nov 21 '23 17:11 artificial-aidan

Hello @artificial-aidan , there is indeed no mechanism that prevents you from using the same ID multiple times. More generally, errors are not yet implemented.

Now that Prismock is stable enough IMO, I'm starting to think about introducing those mechanisms. I might do so after the current issues get fixed.

morintd avatar Nov 21 '23 18:11 morintd

I am interested in the Prismock project, and I noticed the recent issue raised by @artificial-aidan. I was wondering if you have plans to introduce such a mechanism soon.

If you do not have plans to implement this feature in the near future, I would be interested in contributing to the project by implementing it myself. I believe that enforcing ID uniqueness is important for ensuring data integrity, and I would be excited to help improve Prismock in this way.

charlesilieff avatar Mar 05 '24 07:03 charlesilieff

@morintd Hello, interested also in this library, if you may give some directions, maybe we can help?

sledorze avatar Mar 12 '24 14:03 sledorze

Hello @charlesilieff , @sledorze , the search part of @@id is now implemented thanks to @bertrand-sifre but not uniqueness. If you are interested in implementing the feature, feel free to submit a PR 🙏

morintd avatar Apr 27 '24 11:04 morintd

Would it make sense to implement (errors for violating) @unique at the same time? I'm not sure how the behavior differs between those, under the hood.

thw0rted avatar Jun 10 '24 19:06 thw0rted

After #1105 was merged, I was expecting baz.create({data: {fooId, barId}}) to fail when creating a record that links to the ID of a "foo" or "bar" that doesn't exist. I see now that the PR didn't update the "create" delegate so I'm guessing more changes will be needed to support that kind of foreign key check. Does that still fit under the spirit of this ticket, or is a new ticket required?

thw0rted avatar Jan 13 '25 20:01 thw0rted