Skip to content
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

Add DataTable Events #76

Merged
merged 5 commits into from
Apr 10, 2019
Merged

Add DataTable Events #76

merged 5 commits into from
Apr 10, 2019

Conversation

MaximePinot
Copy link
Contributor

Hi,

It can be useful to be able to modify the Query before the iteration starts. I personally need to do this so I can configure the Doctrine cache.

Here's how it works:

$table->createAdapter(ORMAdapter::class, [
    'entity' => Employee::class,
    'query' => function (QueryBuilder $builder) {
        $builder
            ->select('e')
            ->addSelect('c')
            ->from(Employee::class, 'e')
            ->leftJoin('e.company', 'c')
        ;
    },
]);

$table->addEventListener(ORMAdapterEvents::PRE_QUERY, function(ORMAdapterQueryEvent $event) {
    $event->getQuery()->useResultCache(true)->useQueryCache(true);
});

tests/Fixtures/services.yml Show resolved Hide resolved
src/Adapter/Doctrine/ORMAdapterEvents.php Outdated Show resolved Hide resolved
src/Adapter/Doctrine/ORMAdapter.php Outdated Show resolved Hide resolved
src/Adapter/Doctrine/ORMAdapter.php Outdated Show resolved Hide resolved
src/DataTable.php Show resolved Hide resolved
@curry684
Copy link
Member

curry684 commented Apr 9, 2019

The core change we just requested is about keeping 1 central reference to the event dispatcher. Passing it around to the adapters may cause issues in the future.

@MaximePinot
Copy link
Contributor Author

Thank you for your feedback @curry684! Your requested changes are resolved in 04580e7.

@curry684 curry684 requested a review from shades684 April 10, 2019 13:44
@curry684
Copy link
Member

Thank you @MaximePinot!

@curry684 curry684 merged commit e0387ab into omines:master Apr 10, 2019
@MaximePinot MaximePinot deleted the event branch April 15, 2019 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants