cloudcreativity / laravel-json-api

JSON API (jsonapi.org) package for Laravel applications.
http://laravel-json-api.readthedocs.io/en/latest/
Apache License 2.0
780 stars 109 forks source link

Use JOIN instead of multiple SELECTs to include resources #466

Closed half2me closed 4 years ago

half2me commented 4 years ago

I hit my endpoint requesting some resources to be included. I would expect to have SQL JOINs to include those resources, but instead I'm getting a lot of queries, which doesn't scale very well, and also makes it impossible for me to filter based on a related resource. Here is a screenshot of an example request I send, and the queries it ends up generating. image

Details of my adapters and validators are in this issue

In the documentation I read that it uses eager loading by default, so I don't understand why its doing it like this. Am I missing something?

half2me commented 4 years ago

@lindyhopchris could this be anything similar to the previous issue I had? (Linked above)

lindyhopchris commented 4 years ago

We're using Laravel Eloquent eager loading to include related resources, so not actually writing the SQL statements ourselves.

half2me commented 4 years ago

@lindyhopchris So I'm right in assuming these should be JOINs by default?

lindyhopchris commented 4 years ago

I'm not sure off the top of my head how they do it... you'll need to dig into the Laravel code to find out.

half2me commented 4 years ago

@lindyhopchris I realized after searching awhile that this is the way Laravel pulls in included relations. I'm coming from a cakePHP background, where JOINs are the default, hence my confusion.

lindyhopchris commented 4 years ago

No problem! Glad you found the answers you were looking for.