BinarCode / laravel-restify

The fastest way to make a powerful JSON:API compatible Rest API with Laravel.
https://restify.binarcode.com
MIT License
604 stars 54 forks source link

Does not re-give relationships in query type a.b.c #576

Open PHPist opened 1 year ago

PHPist commented 1 year ago

Models relationships

Houses HasMany  Apartments  
Apartments BelongsTo Owner
Apartments BelongsTo House
Owner HasMany  Phones

GET /houses/1?include=apartments.owner.phones returns

https://jsoneditoronline.org/#left=cloud.15ee4ba500164dc9bce7386c5506263b&right=cloud.7126537776eb42c1bd1c35efdb49c4d8

Two apartments in the building (number 50, 88) belong to the same owner. The first object has owner.phones in the second one does not. Alt text

example: https://github.com/PHPist/restify-test

RuslanYakovlev commented 1 year ago

This is relevant for me, can it be fixed?

ibaskakovidurak commented 1 year ago

I have the same problem... I hope guys you fix this bug as soon as possible

npm-fork commented 1 year ago

+1

binaryk commented 1 year ago

Hi @PHPist , thank you for the issue well documented.

Could you ensure please the json URL is correct?

image

PHPist commented 1 year ago

https://jsoneditoronline.org/#left=cloud.7126537776eb42c1bd1c35efdb49c4d8

binaryk commented 1 year ago

The problem is here.

This was a performance enhancement to not load the same data twice from the DB.

Still looking into a good fix:

CleanShot 2023-09-29 at 18 17 56@2x

PHPist commented 1 year ago

Thanks for the quick reply! Yes I saw that and assumed it was an optimization too. We even wanted to figure out how to flesh this out on the front end of the app. But the behavior is very unpredictable. So repeating the relationships would be the right thing to do. Like Laravel does (with, load).