New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to deal with complex SQL query #1626

Closed
lyrixx opened this Issue Jan 5, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@lyrixx
Contributor

lyrixx commented Jan 5, 2018

Hello.

In my app, I have some "complex" queries and I don't really know how to integrate them with API Platform.
I have tried 2 different ways, but the 2 solutions are not perfect.

For now, I will talk about item and not collection. But actually, it's almost the same ;)

Using an extension

Because API Platform automatically applies some join thanks to EagerLoadingExtension it really mess up my query and give me wrong results.
I have tried 2 different things:

  1. set my extension before the EagerLoading: I get more result to extra "left join"
  2. set my extension after: I had to call $qb->resetDQLParts(); ouch

Using a custom DataProvider

Actually, It does the job, but it seems not really natural to me. for the collection, I'm loosing many advantage like the pagination & all.


What is the best way to achieve that?

I saw we can disable the eager-loading. This looks the best idea IMHO, but before doing that, I wanted to be sure what I'm loosing. BTW, we don't you disable this feature by default ? because it could lead to many troubles isn't ?

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Jan 5, 2018

Member

Just use the extensions you want!

I'm doing this a lot:

  1. Create a DataProvider
  2. Inject Extensions manually (not by using a collection), see https://github.com/api-platform/core/pull/1557/files for recent aliases so that Autowiring works
  3. At the end just apply the extensions you want manually (for example the FilterExtension) as we're doing here

If you're doing a native / manual query you don't need EagerLoadingExtension (nor FilterEagerLoadingExtension) because you would probably join manually all your relations.

We don't disable it by default because it has a huge performance impact when relations are serialized.

Member

soyuka commented Jan 5, 2018

Just use the extensions you want!

I'm doing this a lot:

  1. Create a DataProvider
  2. Inject Extensions manually (not by using a collection), see https://github.com/api-platform/core/pull/1557/files for recent aliases so that Autowiring works
  3. At the end just apply the extensions you want manually (for example the FilterExtension) as we're doing here

If you're doing a native / manual query you don't need EagerLoadingExtension (nor FilterEagerLoadingExtension) because you would probably join manually all your relations.

We don't disable it by default because it has a huge performance impact when relations are serialized.

@lyrixx

This comment has been minimized.

Show comment
Hide comment
@lyrixx

lyrixx Jan 5, 2018

Contributor

Ok thanks for you quick and nice answer.

I was thinking the same (about using custom data provider + extension provided by API Platform). But I thought it was too "hacky" to do that, and not so natural. However I don't know why ;)

Just one last question before closing this issue: There are no way to disable for few endpoint the EagerLoadingExtension / FilterEagerLoadingExtension), isn't ?

Contributor

lyrixx commented Jan 5, 2018

Ok thanks for you quick and nice answer.

I was thinking the same (about using custom data provider + extension provided by API Platform). But I thought it was too "hacky" to do that, and not so natural. However I don't know why ;)

Just one last question before closing this issue: There are no way to disable for few endpoint the EagerLoadingExtension / FilterEagerLoadingExtension), isn't ?

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Jan 5, 2018

Member

Just one last question before closing this issue: There are no way to disable for few endpoint the EagerLoadingExtension / FilterEagerLoadingExtension), isn't ?

There is, just disable eager loading at the operation level see here.

But I thought it was too "hacky" to do that

Not hacky, those are meant to be used if you need too :).

Member

soyuka commented Jan 5, 2018

Just one last question before closing this issue: There are no way to disable for few endpoint the EagerLoadingExtension / FilterEagerLoadingExtension), isn't ?

There is, just disable eager loading at the operation level see here.

But I thought it was too "hacky" to do that

Not hacky, those are meant to be used if you need too :).

@lyrixx

This comment has been minimized.

Show comment
Hide comment
@lyrixx

lyrixx Jan 5, 2018

Contributor

Thanks. Good weekend

Contributor

lyrixx commented Jan 5, 2018

Thanks. Good weekend

@lyrixx lyrixx closed this Jan 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment