Giter VIP home page Giter VIP logo

doctrinemongodbbundle's Introduction

DoctrineMongoDBBundle

This bundle integrates the Doctrine2 MongoDB Object Document Mapper (ODM) library into Symfony so that you can persist and retrieve objects to and from MongoDB.

Build Status

Documentation on how to install and use this bundle is available in the Symfony documentation.

Compatibility

The current version of this bundle has the following requirements:

  • PHP 8.1 or newer is required
  • ext-mongodb 1.5 or newer
  • Symfony 6.4 or newer is required

Support for older Symfony, PHP and MongoDB versions is provided via the 4.7.x releases (tracked in the 4.7.x branch). This version sees bug and security fixes only.

doctrinemongodbbundle's People

Contributors

alcaeus avatar avalanche123 avatar bamarni avatar beberlei avatar caciobanu avatar cordoval avatar dbu avatar dependabot[bot] avatar engerim avatar fabpot avatar franmomu avatar greg0ire avatar gromnan avatar henrikbjorn avatar ionbazan avatar jmikola avatar jwage avatar kriswallsmith avatar leek avatar malarzm avatar michaelperrin avatar oriole9g avatar ornicar avatar oskarstark avatar schmittjoh avatar stof avatar szymonkaminski avatar vicb avatar weaverryan avatar wesleyvanopdorp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doctrinemongodbbundle's Issues

Recent commit in symfony/symfony causes declaration error in this bundle.

appears to be this commit broken this bundle.

symfony/symfony@eccc5bd

This cause a declaration error

[ErrorException]                                                                                                                                                                                                                                                                                                                                                               
  Runtime Notice: Declaration of Doctrine\Bundle\MongoDBBundle\Form\Type\DocumentType::getDefaultOptions()
 should be compatible with that of Symfony\Component\Form\AbstractType::getDefaultOptions() in
 .../vendor/doctrine/mongodb-odm-bundle/Doctrine/Bundle/MongoDBBundle/Form/Type/DocumentType.php line 73

I don't want to create a PR since I don't know which repo breaks which repo.

UniqueValidator, current(LoggableCursor) returns null

Its correct behaviour extended from \MongoCursor (first call without next() returns null), but in Symfony UniqueEntityValidator which is used by recent patch is this code:

        $result = $repository->findBy($criteria);

        /* If no entity matched the query criteria or a single entity matched,
         * which is the same as the entity being validated, the criteria is
         * unique.
         */
        if (0 === count($result) || (1 === count($result) && $entity === current($result))) {
            return true;
        }

Already saved unique objects can't be saved again...

AbstractDoctrineExtension not found

I'm trying to use the 2.0 branch of the bundle with Symfony, but it gives me the following error:


Here's what's in my deps file:

target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
version=v2.0.0

I ran bin/vendors install --reinstall and cleared the cache, but I'm still getting the error. What am I doing wrong?

Embed Form with Embed Documents breaks on binding

Hello everyone,

I have a document, let's call it Post which embeds many documents, all from the same collection, let's say Tag. I need to dynamically add tags to a post when I am creating of through it's form.

I have already done it the relational way, following the recipe on the Symfony2 Cookbook.

However when I did so with Mongo I got this error:

Property "tags" is not public in class "Acme\TestBundle\Document\Post". Maybe you should create the method "setTags()"?

I looked in the Document code generated by doctrine:mongodb:generate:document and as Symfony says there is no setTags method. The code looks like:

/**
  * @MongoDB\EmbedMany(targetDocument="Tag")
  */
protected $tags = array();

/**
 * Add tags
 *
 * @param Acme\TestBundle\Document\Tag $tags
 */
public function addTags(\Acme\TestBundle\Document\Tag $tags)
{
    $this->tags[] = $tags;
}

/**
 * Get tags
 *
 * @return Doctrine\Common\Collections\Collection $tags
 */
public function getTags()
{
    return $this->tags;
}

The exception was throw in the Controller, from the action used to implement the Create part of the CRUD, more precisely from within $form->bindRequest($request);

I worked this around by manually adding the setTags in the Document, this way:

public function setTags(ArrayCollection $tags)
{
    $this->tags = $tags;
}

The bind now works and validation and persist aswell. However I am not happy because I don't know if what I did is fine...

I am not very confident with Mongo and Symfony2 so maybe I am missing something, I mean if the generator didn't add the setTags method there must be a reason.

I am missing something here? Otherwise if I have found a problem I would be glad to help to fix it.

Couldn't find the custom method of my Repository

I was following the guide of How to use mongodb with Symfony2(http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html)

I have add a method just like the guide did

// src/Acme/StoreBundle/Repository/ProductRepository.php
namespace Acme\StoreBundle\Repository;
use Doctrine\ODM\MongoDB\DocumentRepository;
class ProductRepository extends DocumentRepository
{
public function findAllOrderedByName()
{
return $this->createQueryBuilder()
->sort('name', 'ASC')
->getQuery()
->execute();
}
}

But When I want use this method:

$product = $this->get('doctrine.odm.mongodb.document_manager')
->getRepository('AcmeStoreBundle:Product')
->findAllOrderedByName();

I got a Undefined method error by symfony:

Undefined method 'findAllOrderedByName'. The method name must start with either findBy or findOneBy!
500 Internal Server Error - BadMethodCallException

[Form] The options "class", "query_builder" do not exist

I'm receiving this message since I updated from dev-master from last week to todays dev-master.

My Formfield looks like this:

$builder->add('locations', 'document', array('class'   => 'test\TestBundle\Document\Location',  'expanded' => true, 'multiple' => true, 'query_builder' => function(DocumentRepository $dm) { return $dm->createQueryBuilder()->addAnd($dm->createQueryBuilder()->expr()->field('status')->notEqual('removed'))->addAnd($dm->createQueryBuilder()->expr()->field('status')->notEqual('office'))->sort('city', 'asc')->sort('locationName', 'asc')->sort('country', 'asc');}));

ServiceNotFoundException: You have requested a non-existent service "doctrine.odm.mongodb"

Everything was fine until I ran "bin/vendors install"

Now I don't know how to fix it
My deps

[symfony]
    git=http://github.com/symfony/symfony.git
    version=v2.0.15

[twig]
    git=http://github.com/fabpot/Twig.git
    version=v1.8.2

[monolog]
    git=http://github.com/Seldaek/monolog.git
    version=1.0.2

[doctrine-common]
    git=http://github.com/doctrine/common.git
    version=2.2.1

[doctrine-dbal]
    git=http://github.com/doctrine/dbal.git
    version=2.2.1

[doctrine]
    git=http://github.com/doctrine/doctrine2.git
    version=2.2.1

[swiftmailer]
    git=http://github.com/swiftmailer/swiftmailer.git
    version=v4.1.7

[assetic]
    git=http://github.com/kriswallsmith/assetic.git
    version=v1.0.3

[twig-extensions]
    git=http://github.com/fabpot/Twig-extensions.git

[metadata]
    git=http://github.com/schmittjoh/metadata.git
    version=1.0.0

[SensioFrameworkExtraBundle]
    git=http://github.com/sensio/SensioFrameworkExtraBundle.git
    target=/bundles/Sensio/Bundle/FrameworkExtraBundle
    version=origin/2.0

[JMSSecurityExtraBundle]
    git=http://github.com/schmittjoh/JMSSecurityExtraBundle.git
    target=/bundles/JMS/SecurityExtraBundle
    version=origin/1.0.x

[SensioDistributionBundle]
    git=http://github.com/sensio/SensioDistributionBundle.git
    target=/bundles/Sensio/Bundle/DistributionBundle
    version=origin/2.0

[SensioGeneratorBundle]
    git=http://github.com/sensio/SensioGeneratorBundle.git
    target=/bundles/Sensio/Bundle/GeneratorBundle
    version=origin/2.0

[AsseticBundle]
    git=http://github.com/symfony/AsseticBundle.git
    target=/bundles/Symfony/Bundle/AsseticBundle
    version=v1.0.1

[KnpMenu]
    git=https://github.com/KnpLabs/KnpMenu.git

[KnpMenuBundle]
    git=https://github.com/KnpLabs/KnpMenuBundle.git
    target=bundles/Knp/Bundle/MenuBundle

[FOSUserBundle]
    git=git://github.com/FriendsOfSymfony/FOSUserBundle.git
    target=bundles/FOS/UserBundle

[ICEFlashMessageBundle]
    git=git://github.com/nielskrijger/FlashMessageBundle.git
    target=/bundles/ICE/FlashMessageBundle

[doctrine-fixtures]
    git=http://github.com/doctrine/data-fixtures.git

[DoctrineFixturesBundle]
    git=http://github.com/doctrine/DoctrineFixturesBundle.git
    target=/bundles/Symfony/Bundle/DoctrineFixturesBundle
    version=origin/2.0

[faker]
    git=git://github.com/fzaninotto/Faker.git
    target=/faker

[BazingaFakerBundle]
    git=git://github.com/willdurand/BazingaFakerBundle.git
    target=/bundles/Bazinga/Bundle/FakerBundle

[doctrine-mongodb]
    git=http://github.com/doctrine/mongodb.git
    version=1.0.0-BETA1

[doctrine-mongodb-odm]
    git=http://github.com/doctrine/mongodb-odm.git
    version=1.0.0-BETA5

[DoctrineMongoDBBundle]
    git=http://github.com/doctrine/DoctrineMongoDBBundle.git
    target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
    version=v2.2.0

deps.lock

symfony v2.0.15
twig v1.8.2
monolog 1.0.2
doctrine-common 2.2.1
doctrine-dbal 2.2.1
doctrine 2.2.1
swiftmailer v4.1.7
assetic v1.0.3
twig-extensions feb6d3f10c411e2631997c0a905aa581c80305c1
metadata 1.0.0
SensioFrameworkExtraBundle 1eda94d838aa885e154f92f426df35f2252cdb92
JMSSecurityExtraBundle e752f888c51425f71382c056961f10f2be642102
SensioDistributionBundle 41a6c5caed65f02bb09c95a90579f047616471fd
SensioGeneratorBundle 83b768a487a6878f2bc2ad6859bd61a3651a7885
AsseticBundle v1.0.1

Problem with gridfs when using cache

When I attempt to save a document with an attachment, an exception is thrown :

MongoException: zero-length keys are not allowed, did you use $ with double quotes? (uncaught exception) at _/vendor/doctrine-mongodb/lib/Doctrine/MongoDB/Collection.php line 146

But when i restart my apache server, the document is normally saved without any exception. But the second time, when saving a new document, the exception is thrown again.

Strange...
Seeing my configuraytion file, I comment the parameter metadata_cache_driver: apc. And then, the problem disappears.

Adding a DocumentInitializer

The Validator component now contains the concept of initializers called before performing the validation. The goal is to support proxies by initializing them before validating the properties as it uses reflection.
The ORM implementation is here with the service definition
There is 2 issues to reproduce the implementation in MongoDB: there is no registry to find the good entity manager (see #31 which adds it) and the UnitOfWork does not have the initializeObject method which is implemented by the ORM.

DocumentTypeTest fails with Symfony 2.1-RC1 Forms

For reference:

Existing test suite using Symfony 2.1:

$ phpunit 
PHPUnit 3.6.11 by Sebastian Bergmann.

Configuration read from /home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/phpunit.xml.dist

......S.....................................................EF... 65 / 71 ( 91%)
......

Time: 1 second, Memory: 15.25Mb

There was 1 error:

1) Doctrine\Bundle\MongoDBBundle\Tests\Form\Type\DocumentTypeTest::testDocumentManagerIsReturnedWhenGettingEm
OutOfBoundsException: The option "preferred_choices" does not exist.

/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Options.php:227
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Options.php:350
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php:84
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Options.php:466
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Options.php:308
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php:231
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/Tests/Form/Type/DocumentTypeTest.php:52

--


There was 1 failure:

1) Doctrine\Bundle\MongoDBBundle\Tests\Form\Type\DocumentTypeTest::testExceptionWhenDocumentManagerAndEmIsSet
Failed asserting that exception of type "OutOfBoundsException" matches expected exception "InvalidArgumentException".


FAILURES!
Tests: 71, Assertions: 337, Failures: 1, Errors: 1, Skipped: 1.

If I move the parent::setDefaultOptions($resolver); call to the bottom of DocumentType::setDefaultOptions() (instead of having it on the first line), we get:

$ phpunit 
PHPUnit 3.6.11 by Sebastian Bergmann.

Configuration read from /home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/phpunit.xml.dist

......S.....................................................E.... 65 / 71 ( 91%)
......

Time: 0 seconds, Memory: 15.25Mb

There was 1 error:

1) Doctrine\Bundle\MongoDBBundle\Tests\Form\Type\DocumentTypeTest::testDocumentManagerIsReturnedWhenGettingEm
Symfony\Component\OptionsResolver\Exception\InvalidOptionsException: The option "em" does not exist. Known options are: "document_manager"

/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php:255
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php:189
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/Form/Type/DocumentType.php:69
/home/jmikola/workspace/doctrine/DoctrineMongoDBBundle/Tests/Form/Type/DocumentTypeTest.php:48

FAILURES!
Tests: 71, Assertions: 340, Errors: 1, Skipped: 1.

That makes sense, since the em and other options are not defined until the parent method is called.

[doctrine:mongodb:mapping:info] InvalidArgumentException: parameter "doctrine.odm.mongodb.default_document_manager" must be defined

When I run doctrine:mongodb:mapping:info --verbose, I get the following exception:

[InvalidArgumentException]                                                      
  The parameter "doctrine.odm.mongodb.default_document_manager" must be defined.  

Exception trace:
 () at /var/www/dev/linx/symfony/app/cache/dev/appDevDebugProjectContainer.php:2501
 appDevDebugProjectContainer->getParameter() at /var/www/dev/linx/symfony/vendor/bundles/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php:50
 Symfony\Bundle\DoctrineMongoDBBundle\Command\InfoDoctrineODMCommand->execute() at /var/www/dev/linx/symfony/vendor/symfony/src/Symfony/Component/Console/Command/Command.php:214
 Symfony\Component\Console\Command\Command->run() at /var/www/dev/linx/symfony/vendor/symfony/src/Symfony/Component/Console/Application.php:194
 Symfony\Component\Console\Application->doRun() at /var/www/dev/linx/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:75
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/dev/linx/symfony/vendor/symfony/src/Symfony/Component/Console/Application.php:118
 Symfony\Component\Console\Application->run() at /var/www/dev/linx/symfony/app/console:19

The problem is in Symfony\Bundle\DoctrineMongoDBBundle\Command\InfoDoctrineODMCommand at line 50:

48  $documentManagerName = $input->getOption('dm') ?
49      $input->getOption('dm') :
50      $this->getContainer()->getParameter('doctrine.odm.mongodb.default_document_manager');

The command works as expected when I change $this->getContainer()->getParameter('doctrine.odm.mongodb.default_document_manager') to 'default'.

getQuery(array('multiple'=>true)) is not working

Hi!
I dont know if its a problem with doctrine-mongodb-odm or DoctrineMongoDBBundle.
I am trying to do something like this:

$parameters->createQueryBuilder()
->update()
->field('id')->equals($tk)
->field('children.fieldtype')->equals('checkbox')
->field('children.$.value')->set(0)
->getQuery(array('multiple'=>true))
->execute();

The result according to the log is:

db.parameters.update({ "_id": "system-site", "children.fieldtype": "checkbox" }, { "$set": { "children.$.value": 0 } });

I guess its just "multiple": true that is missing.

Thank you and sorry about my bad english :)

Need to use Mongo as a service

I need to inject the \Mongo object into Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler

I tried declaring MongoDoctrine\MongoDB\Connection as a service which I get by setting doctrine.odm.mongodb.document_manager as factory_service and getConnection as factory_method. From there, I would get the \Mongo instance through getMongo. But sometimes it returns null.

So how to share the \Mongo instance between doctrine and my session handler?

"Query Logging is Disabled" - Not sure why?

Situation:

I'm in the process of trying to get the sensio/framework-extra-bundle's DoctrineParamConverter working with MongoDB.

Problem:

Unfortunately, I can't really tell if the DB is being queried at all, because when I go to the Symfony Profiler and click the "Doctrine MongoDB" tab, I get the message "Query logging is disabled."

I'm fairly certain I have the MongoDB Bundle up and running in my project, as I don't think I'd be getting this tab otherwise.

The real confusion is that by all accounts, I think I should be getting logging by default while in development mode. In Configuration.php, I'm seeing:

    ->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
    ->arrayNode('profiler')
        ->addDefaultsIfNotSet()
        ->treatTrueLike(array('enabled' => true))
        ->treatFalseLike(array('enabled' => false))
        ->children()
            ->booleanNode('enabled')->defaultValue('%kernel.debug%')->end()
            ->booleanNode('pretty')->defaultValue('%kernel.debug%')->end()
        ->end()

Here's the chunk of YAML that I'm using to configure things:

    doctrine_mongodb:
      connections:
          default:
              server: mongodb://localhost:27017
              options:
                  connect: true
      default_database: nerve
      document_managers:
          default:
            auto_mapping: true

So, even if there was an issue with my ParamConverter - at the very least I should be able to see whether queries have been run or not by simply adding the MongoDB Bundle to my kernel and checking it in the profiler.

This does not appear to be the case. Thanks for hearing me out!

Symfony2 beta2 : conflict with dependency injection component

Hello,
I just come to start a new project with the last version of symfony-standard ,
After the installation of DoctrineMongoDBBundle I get this exception :

Fatal error: Cannot use object of type Symfony\Component\DependencyInjection\Reference as array in .../vendor/bundles/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php on line 19

DoctrineMongoDBBundle can't search value in hash

I have document with hash field:

{ "_id" : ObjectId("501d736fd940d76b0f000002"), "categories" : [ 1, 2, 3 ] }

PHP code to search by category (in repository class):

<?php
return $this->createQueryBuilder()->field('categories')
    ->equals($categoryId)->getQuery()->execute();

This code generates absolutely working query: db.recipe.find({ "categories": 2 }).sort([ ]); (In profiler's query log). When I copypaste this query to console client it works well, but in repository class it returns nothing.

When I ran this query in plain PHP like this:

<?php
$mongo = new Mongo();
$col = $mongo->test_database->recipe;

foreach ($col->find(array("categories" => 2)) as $r) {
  print_r($r);
}

i got result. Or when I search value with scalar type I got result. But searching in array field returns nothing.

Checked both MongoDB 2.1.1 and 1.8.1. My deps file is:

[symfony]
    git=http://github.com/symfony/symfony.git
    version=origin/2.0

[doctrine-common]
    git=http://github.com/doctrine/common.git
    version=2.2.2

[doctrine-dbal]
    git=http://github.com/doctrine/dbal.git
    version=2.1.7

[doctrine]
    git=http://github.com/doctrine/doctrine2.git
    version=2.1.7

[doctrine-mongodb-odm]
    git=http://github.com/doctrine/mongodb-odm.git

[DoctrineMongoDBBundle]
    git=http://github.com/doctrine/DoctrineMongoDBBundle.git
    target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
    version=origin/2.0

PHP MongoDB lib version = 1.2.12

Create unit tests

The testsuite does not do unit tests currently: the tests for the form type require a running mongo server instead of mocking the dependencies of the class, and it is the same for other tests

Recent commits broke Symfony2 Integration

We have been working with the combination of versions listed at the bottom of this email for several months now but a recent change to the doctrine/mongo-odm (I think) repo broke this. We are now getting the following error:

Fatal error: Class 'Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain' not found...

Here are the Mongo versions in use:

[doctrine-common]
git=http://github.com/doctrine/common.git
version=2.2.1

[doctrine-dbal]
git=http://github.com/doctrine/dbal.git
version=2.2.1

[doctrine]
git=http://github.com/doctrine/doctrine2.git
version=2.2.1

[doctrine-mongodb]
git=http://github.com/doctrine/mongodb.git

[doctrine-mongodb-odm]
git=http://github.com/doctrine/mongodb-odm.git

[DoctrineMongoDBBundle]
git=git://github.com/doctrine/DoctrineMongoDBBundle.git
target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
version=v2.0.1

UniqueValidator is invalid with master

Fatal error: Call to undefined method Symfony\Component\Validator\ExecutionContext::setPropertyPath() in /Volumes/Kermode/Projects/Play/ProjectName/vendor/doctrine/mongodb-odm-bundle/Doctrine/Bundle/MongoDBBundle/Validator/Constraints/UniqueValidator.php on line 84

Add version numbers to the installation instructions

If you try to install the DoctrineMongoDBBundle as it is described in the documentation it won't work. The problem is that the given deps file doesn't define a certain version of the bundle and obviously there is a BC break with the master branch, because "AbstractDoctrineExtension" cannot be found.

So I think it would be a good idea to add a

version=v2.0.1

to the deps file snippet for Symfony v.2.0.8 and maybe start to maintain a list of compatible Symfony/DoctrineMongoDBBundle versions? Another possibility would be to give a list of recommended versions for all the bundles in the Symfony documentation for the certain Symfony versions and just give an explanation on how to use a certain version of the bundle here.

[Form][DocumentType] Multiple mode and remove associations

When i build my form with something like that :

<?php
//.....
 $builder->add('actors', 'document', array( 'multiple' => 'true',  
'class' => 'Admingenerator\\DoctrineODMDemoBundle\\Document\\Actor',));

I can associate actors to my movie, but i can't remove them, do you know why ?

Note if i make a var_dump in my data class Movie

<?php
//.....
    public function setActors(\Doctrine\Common\Collections\ArrayCollection $actors)
    {
        var_dump($actors);
         $this->actors = $actors;
    }

the ArrayCollection is good. Bug in persist ??

packagist - Index invalid or out of range

Unless I configured composer wrong, this doesn't work:

"doctrine/mongodb-odm-bundle": "v2.0.1"

All I get when I run php composer.phar update is:

"RuntimeException]
Index invalid or out of range"

Unique constraint doesn't work with embedded document

I'm trying to use the "unique validator", but I get this error:
[BadMethodCallException] Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::getAssociationTargetClass($assocName) is not implemented yet.

Am I doing something wrong?

I use Symfony 2.1, and latest bundles/projects versions.

The unique constraint works with a "normal" document, but it doesn't work with an embedded document.

I also created an issue on doctrine/mongodb-odm because I'm not sure where is the problem:
doctrine/mongodb-odm#295

RFC: Release tags

In Exercise/FOQElasticaBundle@60d3ef6, I was discussing with Richard about bundle tagging for Symfony 2.0 and 2.1 compatibility branches. Based on that conversation, I propose the following for this bundle:

  • 1.0 - Symfony 2.0 compatibility before the mapping refactoring of #124, which bumped the Common requirement to 2.2+. This will be fixed to an older version of ODM, of course.
  • 1.1 - Symfony 2.0 compatibility with Common 2.2+ (2.0 branch)
  • 2.0 - Symfony 2.1 compatibility with Common 2.2+ (master branch)

mongodb currently has no tags, so we can cut a 1.0-beta1 of that. For mongodb-odm, the next tag would be 1.0-beta4. Since 1.0 of this bundle would need to precede the mapping refactoring (Common 2.2+), I suggest we create 1.0-beta4 on ODM before that was done with doctrine/mongodb-odm#350 and doctrine/mongodb-odm#370. And then immediately create a 1.0-beta5 tag on master.

Thoughts?

Authentication against wrong database

I'm getting what appears to be incorrect behavior when asking this bundle to connect me to a MongoDB with authentication. Essentially, it appears that authentication is performed against the 'admin' database instead of the database specified in the default_database field according to the documentation.

This is the configuration I am using:

doctrine_mongodb:
    connections:
        default:
            server: mongodb://%mongo_host%
            options:
                username: %mongo_user%
                password: %mongo_password%
    default_database: %mongo_database%

This causes authentication to fail in Doctrine\MongoDB\Connection at line 98, with the following exception message:

Couldn't authenticate with database admin: username [myuser]

When I change the configuration to the following, everything works fine:

doctrine_mongodb:
    connections:
        default:
            server: mongodb://%mongo_user%:%mongo_password%@%mongo_host%
    default_database: %mongo_database%

The other workaround is to leave the initial configuration but add the user to the 'admin' database, however it's not a good idea to have users running with admin rights.

mongodb:generate:documents adds duplicate properties/getters/setters on subclass when using inheritance

Start with these two Documents:


namespace My\XBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 * @MongoDB\InheritanceType("COLLECTION_PER_CLASS")
 */
abstract class AbstractFoo
{
    /**
     * @MongoDB\Id
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $displayName;
}

namespace My\XBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class SubFoo extends AbstractFoo
{
    /**
     * @MongoDB\String
     */
    protected $value;
}

Now, when you run mongodb:generate:documents My\XBundle, you will end up with this in the subclass:


namespace My\XBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class SubFoo extends AbstractFoo
{
    /**
     * @MongoDB\String
     */
    protected $value;

    /**
     * @var $id
     */
    protected $id;

    /**
     * @var string $displayName
     */
    protected $displayName;


    /**
     * Set value
     *
     * @param string $value
     */
    public function setValue($value)
    {
        $this->value = $value;
    }

    /**
     * Get value
     *
     * @return string $value
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * Get id
     *
     * @return id $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set displayName
     *
     * @param string $displayName
     */
    public function setDisplayName($displayName)
    {
        $this->displayName = $displayName;
    }

    /**
     * Get displayName
     *
     * @return string $displayName
     */
    public function getDisplayName()
    {
        return $this->displayName;
    }
}

Generate document command does not work in subfolder document in yml format

I have a document in Acme\DemoBundle\Document\Product\Car.php which extends Acme\DemoBundle\Document\BaseProduct.php.
I'm using yml for the mapping.

when I run doctrine:mongodb:generate:documents this exception occured
[Doctrine\ODM\MongoDB\MongoDBException]
No mapping found for field '/xxx/testing/src/Acme/DemoBundle/Resources/config/doctrine/Car.mongodb.yml' in class 'Acme\DemoBundle\
Document\Car'.

It's strange. I actually put the mapping in Acme/DemoBundle/Resources/config/doctrine/product/Car.mongodb.yml, but it search in the parent folder.

NB: It works in annotation format.

The fields "0" were not expected

HI,

I use Symfony 2 and the bundle DoctrineMongoDBBundle, I access the data, I write data, all going well except when I use the Field type "document" on one of my form, when i submit I get the error: The fields "0" were not expected

And i get this message as many elements has been selected in the list.

The Form Type code :

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);

    $builder->add('templates', 'document', array(
        'class' => 'Dofa\ManagerBundle\Document\Template',
        'multiple' => 'true',
        'expanded' => 'true',
        'property' => 'name'                    
    ));
}

The view :

<form id="form_user_template" action="{{ path('DofaManagerBundle_user_edit_process', {'id':'4f45268b86b4484c10000000'}) }}" {{     form_enctype(formTemplate) }} method="POST" class="fos_user_profile_edit">
    {{ form_rest(formTemplate) }}
    <button class="blue-button" type="submit">Submit</button>
</form>

Any idea where i could come from ? it's seems that everytime i use a collection with a "ReferenceMany" annotations it doesn't work properly.

Thanks

Catchable Fatal Error: Argument 1 passed to Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::__construct()

I have just updated to symfony beta 4 with the newest DoctrineMongoDBBundle / doctrine-mongodb / doctrine-mongodb-odm and got

Catchable Fatal Error: Argument 1 passed to Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::__construct() must be an instance of Doctrine\Common\Annotations\AnnotationReader, instance of Doctrine\Common\Annotations\FileCacheReader given, called in C:\xampp\htdocs...\app\cache\dev\appDevDebugProjectContainer.php on line 260 and defined in C:\xampp\htdocs...\vendor\doctrine-mongodb-odm\lib\Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver.php line 73

Custom Types

I had an idea to create a better flow for handing uploaded files in Symfony2 through a custom type that would mape the file from File to a string and then back again. Unfortunately there is no place to add a custom type like in DoctrineBundle.

Theese are some of the things i have tried.

  1. In a bundles build method. This is unfortunately only ran when the Container is build.
  2. in a bundles boot method but that is too late because of Doctrine Bundle being enabled before my custom one.

Any further ideas without implementing this directly would be good ;)

Misleading generator error when MongoDB service not configured

Running php app/console doctrine:mongodb:generate:documents $BUNDLENAME in a Symfony 2.1 project where doctrine_mongodb has no configuration defined, always leads to the following error message:

[RuntimeException]
Bundle $BUNDLENAME does not contain any mapped documents.

This is misleading when there are mapped documents in the bundle, as the actual issue is that doctrine_mongodb isn't configured. Once the configuration is set, the generator works fine with the same command that was initially used.

The error message should be updated to indicate the correct issue.

Mapping type RAW can't handle multi-level

I have an Document with field called "$foo" mapped to "Raw", like this:

/**
 * @MongoDB\Raw
 */
private $foo;

When I do the following query:

->upsert()
->field('type')->equals('analytics-foo-bar')
->update()
->field("foo.bar.level3a")->inc(1)
->field("foo.bar.level3b")->inc(1)

My expected result was:

{
  "type": "analytics-foo-bar",
  "foo": {
    "bar": {
      "level3a": 1,
      "level3b": 1,
    }
  }
}

But the real result was:

{
  "type": "analytics-foo-bar",
  "foo": {
    "bar": 1
  }
}

SingleCollectionInherance and generate documents

When you use Single Collection Inheritance the command php app/console doctrine:mongodb:generate:documents throw a exception

[Doctrine\ODM\MongoDB\MongoDBException]
No identifier/primary key specified for Document 'Savedcite\CiteBundle\Document\CiteBook'. Every Document must have an identifier/primary key.

So the problem is that it not check the parent class ;(

values for multiple, expanded DocumentType are not loaded

I am trying to print a multiple, expanded form widget(ie: checkboxes) loading its options from mongo. Using the following annotation and letting the form guess everything(or specifing 'document', array('multiple' => true, 'expanded' => true, 'class'=>...)) it works fine when it comes to rendering and submitting:

/**
 * @var \Doctrine\Common\Collections\ArrayCollection
 *
 * @MongoDB\EmbedMany(targetDocument="Pizzas")
 */
protected $pizzas;

Where I am experiencing troubles is on showing results on edit pages.
Even if the Document is loaded properly, the checkboxes don't get "checked".
I found a potential source of the problem in Symfony\Bundle\DoctrineMongoDBBundle\Form\DataTransformer\DocumentsToArrayTransformer.php, line 55,
where $array[] = $this->choiceList->getIdentifierValue($document); gets called.
Following the flow, I got to Doctrine\ODM\MongoDB\UnitOfWork, method getDocumentIdentifier(): that function checks for the spl_object_hash($document) key into $this->documentIdentifiers and eventually return the corresponding value. The point is that spl_object_hash() won't return the Document (Mongo)id, but one of its own that will never match the ones loaded as choices for the checkboxes, determining the lack of selected options in the editing page.
Changing $array[] = $this->choiceList->getIdentifierValue($document); to $array[] = $document->getId(); in DocumentsToArrayTransformer solves this problem, but I am not sure it's the "right" solution to this problem.

Symfony 2.1beta3 with DoctrineMongoDBBundle

This was sent to my email, I'm creating an issue here, hoping someone can help with the described problem:

I'm currently working on a Symfony 2.1 project with MongoDB and I encounter some issues. I would like to combine it with the Admingenerator GeneratorBundle.

The Doctrine MongoDB ODM is now made by Doctrine and when I try to load it in my AppKernel.php, it says that the Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle class is not found.

In my autoload.php, located in the app folder, I've added the following lines :

AnnotationRegistry::registerFile(
   __DIR__.'/../vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php'
);

Nevertheless, It's not working, and everything I found on the Internet does not match with Symfony 2.1 Beta3 version.

If you may help me, I would very appreciate it.

Thank you in advance,

Pierre

MongoDB ParamConverter

I've just created a ParamConverter for the symfony routing component and mongodb documents.


    /**
     * controller
     *
     * @Route("/{id}/todos.{_format}", name="todos_list",
     *   defaults={"_format"="json"}
     * )
     * @ParamConverter("list", class="Cypress\FooBundle\Document\MongoDB\TodoList")
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function listAction(TodoList $list)

It's just a port from the doctrine one, not so much work indeed. Anyway, do you think that this could be useful for a pull request in this bundle?

Many thanks to you all for the great work.
Regards.

[Form] ChoiceList::addChoices() must be of the type array, object given

(ref. from #129)

I'm receiving the same error as khepin mentioned in #129 with latest master-dev build.

if needed, here is my form:

$builder->add('location', 'document', array('class' => 'test\TestBundle\Document\Location'));

Really rudimentary.
I'll look tomorrow, if I can created a unittests for this issue (not yet created one in php, c/c++ only).

is not a valid entity or mapped super class, when using 'entity'-field in abstractType

Hello,

im having a problem using the entity field inside of an abstract class.

I have an entity which references another entity and i want the referenced entites stored in db to be selectable from inside of a form.

######################## the entity referencing the other entity
add('wheel', 'entity', array( 'class' => 'Car\\DealerBundle\\Document\\Wheel' )); ``` ###### I replaced the classnames and namespace-names, so don't care about the stupid example :D Im getting the following error: Class Car\DealerBundle\Document\Wheel is not a valid entity or mapped super class. MappingException ::classIsNotAValidEntityOrMappedSuperClass Whats the problem here?

[Form] "empty_value => true" and "required => false" won't render an empty value for document Field Type

(related to #2802 from symfony)

$builder->add('name', 'document', array('class' => 'test\TestBundle\Document\Name', 'multiple' => true, 'empty_value' => true, 'required' => false, 'label' => 'Name:', 'query_builder' => function(DocumentRepository $dm) { return $dm->createQueryBuilder()->sort('name', 'asc');},));

Will render all documents, that got fetched by query_builder, but not an empty value in select-form-field.
Only setting 'required' => false or 'empty_value' => true results to the same issue.

Tested with 2.0.6 and 2.1.0-dev (from today).

adding the following to the twig-view, creates the empty value:

{{ form_widget(form.name, { 'empty_value' : '' }) }}

but choosing the empty value makes the form invalid.

Add service hook for packagist to this repo

I'm just guessing that the service hook for packagist isn't set up on this repo. The last commit was 2 hours ago and packagist still hasn't crawled the changes yet. Couldn't hurt to add it. Thanks.

incompatibility with DoctrinePHPCRBundle

Both bundles use the doctrine.common.event_subscriber and doctrine.common.event_listener. This does not make sense to use common in the name and makes them incompatible as a listener is specific to an ODM.
It should probably be changed to doctrine.mongodb.event_listener.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.