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

Getter from custom cast is not executed when accessing related models #1849

Closed vesper8 closed 5 months ago

vesper8 commented 5 months ago

Environment

No response

Reproduction

related to https://github.com/CodeDredd/pinia-orm/issues/1818

Describe the bug

I'm using a custom cast with one of my model fields and that cast provides a getter and a setter.

I just noticed that when I load related models, the getter is not being executed. It is executed fine when I query the model directly but not if I load a parent model.

So here it works well

const requirements = useRepo(Requirement).all()

console.log(requirements); // here the cast is applied and the getter is used

but here it doesn't

const architectureView = useRepo(ArchitectureView) //
  .with('requirements')
  .where('id', this.currentArchitectureView.id)
  .first();

console.log(architectureView.requirements); // here the cast is not applied and the getter is not used

I believe this is a bug right? If it's intended.. is there a way to circumvent that so the getter is always used?

Thanks!

Additional context

No response

Logs

No response

CodeDredd commented 5 months ago

Yeah i think this is a bug. Looking into it.

vesper8 commented 5 months ago

@CodeDredd Great thank you!

If possible I would like to know if you foresee being able to push this fix to the edge channel very soon? I ask because I'm working on a demo for next Monday and without this fix I can still make it work but I have to add quite a lot of extra code to do the work of the getter in many places.

CodeDredd commented 5 months ago

@vesper8 If you spend my a ☕ i push it very soon. 😉 😄 ... i like brain motivation. ^^

I see what i can do. 😉

vesper8 commented 5 months ago

@vesper8 If you spend my a ☕ i push it very soon. 😉 😄 ... i like brain motivation. ^^

I see what i can do. 😉

Not sure how much a ☕ goes for in Germany but I just PayPal'd you a little something that should keep you well caffeinated for a few days at least ;-)

Many thanks for all your hard work on this very important library.

CodeDredd commented 5 months ago

@vesper8 Many thanks ❤️ ❤️ . This is enough for 3 coffees. So that's enough for one day 😆 .... hehehe.... anyway thanks. It's always nice to see to get something back 💯

I hope i was fast enough with the fix....hehehe ^^....it seemed only to have affacted belongsToMany and morphToMany

vesper8 commented 5 months ago

@CodeDredd Thank you very much once more! I can confirm that your fix is working on the edge channel. I was indeed having this issue with belongsToMany relations.

Cheers!!