omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
259 stars 114 forks source link

Using the MongoDB Adaptor #21

Closed marcusorjames closed 6 years ago

marcusorjames commented 6 years ago

Hi, Does anyone have any examples of how to implement this with Doctrine MongoDB. The Adaptor seems to need to take a Collection how would I create this and then pass it in? The documentation just shows a string which is obviously incorrect. I've tried passing in for example from the document manager:

$documentManager = $this->container->get('doctrine.odm.mongodb.document_manager');
$collection = $documentManager->getDocumentCollection('AppBundle\Document\Reservation');

table = $this->createDataTable()
            ->add('guest', TextColumn::class)
            ->add('reference', TextColumn::class)
            ->createAdapter(MongoDBAdapter::class, [
                'collection' => $collection,
            ])
            ->handleRequest($request);

But this returns a "LoggableCollection" which fails the options validation, allowing a LoggableCollection then throws a "Projection cannot have a mix of inclusion and exclusion."

I feel I am missing something obvious here / MongoAdaptor isn't finished yet.

If anyone can help that would be great, I love the way this bundle is written and would love to use it.

giovannialbero1992 commented 6 years ago

Hi @marcusorjames, this adapter is written to be used with MongoDB extension. For doctrine ODM, I've written a PR #18 that introduce DoctrineODM Adapter.

If you want to try this adapter you can declare a class ODMAdapter and copy the content of my file into your a class and in createAdapter method you can pass your custom adapter.

Let me know!

marcusorjames commented 6 years ago

Amazing, yup thought I was missing something obvious. I will give it a go :)

curry684 commented 6 years ago

MongoAdaptor isn't finished yet.

While more or less true, we're actually using it internally in production, just not in a very fancy way :)

The provided MongoDBAdapter is indeed as @giovannialbero1992 stated meant to 'adapt' the MongoDB extension itself.

Keep us posted if you run into any issues so we can improve it together!

marcusorjames commented 6 years ago

Right, so I am using Symfony 3 PHP7 with the alcaeus/mongo-php-adapter, looking at it it looks like mongodb-odm uses an old version of mongo-ext which the above adaptor is a work around: https://stackoverflow.com/questions/36964171/php-7-with-doctrine-mongodb-odm

So I am getting the "Install doctrine/mongodb-odm-bundle to use the ODMAdapter" exception.

Not sure what magic injects the registry into the adaptor extension?

Any ideas?

giovannialbero1992 commented 6 years ago

@marcusorjames do you have installed doctrine/mongodb-odm-bundle ? If yes you should have "autowire" set to true and declare into service.yaml

    Doctrine\Bundle\MongoDBBundle\ManagerRegistry:
        alias: 'doctrine_mongodb'
curry684 commented 6 years ago

Closing as inactive.