CodeDredd / pinia-orm

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
https://pinia-orm.codedredd.de/
MIT License
452 stars 39 forks source link

Deleting items from the repository doesnt work in some cases #1730

Closed garma83 closed 1 year ago

garma83 commented 1 year ago

Environment

No response

Reproduction

Please let me know if you need one. I dont have time right now but can make it later if desired

Describe the bug

This is a new problem since I updated piniaORM last week

I have a model with a parent and a child. Parent is called Location, child is called Feature. The relationship is ManyToOne

I am inserting Feature data for a specific Location using useRepo(Feature).insert(array). When inserting it, the instances dont have an id, so they get assigned a string ID by PiniaORM. They do have a locationId (also a string id)

NOTE: im noticing that:

Next, I want to delete the same data. I query for the features as follows: useRepo(Feature).query().where('locationId', locationId).delete()

When I verify that the data is gone, its not deleted: useRepo(Feature).query().where('locationId', locationId).get().

I also tried to query for the features and then mapping them to an array, and then calling useRepo(Feature).destroy(ids), which also doesnt work. I did notice though that the id's of the Features have number ID's now. I suspect this is the reason. I'm not sure where those number IDs come from

Additional context

The Feature model has a 'properties' attribute. Im noticing that whether this property is there influences the problem. If its not there, im not getting number IDs assigned. does that ring a bell?

Logs

No response

garma83 commented 1 year ago

I had to roll back to 1.4.0 to make this go away

garma83 commented 1 year ago

I resolved this issue. For anyone who finds this in the future... It turns out newer versions of pinia-orm return the actual reactive object from queries, instead of a copy, which happened before.

In a different part of my code I was modifying data which then interfered with code like below (I changed id's etc)