CodeDredd / pinia-orm

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

Let us specify which relations to load when using withAllRecursive ? #1726

Open vesper8 opened 11 months ago

vesper8 commented 11 months ago

Describe the feature

Right now I want to use withAllRecursive but it's incredibly slow and I believe that's because it loads relationships recursively both up and down.. meaning that it loads all relations including belongsTo and hasMany recursively which creates a recursive loop and crashes my app.

I would like to specify which relations to load recursively so that I only load child relations and ignore parent relations.

Is there any chance you could add this functionality? Or can I already do this by passing a callback to withAll ?

Additional information

Final checks

CodeDredd commented 9 months ago

You are absolutly right. You can end in relation "loop" if the child has again a relation to the parent. I have to think about it first what the smart solution for this is. Surly it would be already good if the relations could be defined. Trying to add this first and then maybe working on a better withAllRecursive solution

vesper8 commented 9 months ago

Thanks.. yes I do think this is a problem area right now. both withAll and withAll recursive are very bad for performance. This wasn't the case with vuex-orm, not sure why. This has led me to be more strict when defining which relations I want loaded.. which is fine and is probably better anyway as withAll and withAllRecursive are kind of "lazy" methods anyway. Still I think it would be good to look into it, or maybe add a warning of the potential performance pitfalls of these helpers.