doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

PersistentCollectionException: You must configure a PersistentCollection directory. See docs for details. #1415

Closed davidrojo closed 8 years ago

davidrojo commented 8 years ago

Hello,

I am trying to use custom collection classes (https://github.com/doctrine/mongodb-odm/pull/1219) as I've seen this is a new feature for 1.1 and It's really very awesome. I've changed my composer to require dev-master branch in a Symfony 2 project.

I've got this in my Document/Section.php

/**
 * @MongoDB\Document
 * @HasLifecycleCallbacks
 */
class Section
{

  .....

    /** 
     * @MongoDB\EmbedMany(
     *     collectionClass="\DelfosBundle\Utils\Collections\SortedCollection",
     *     targetDocument="Restriction"
     * )
     */
    private $restrictions = array();

    /*** more code ***/
}

And in \DelfosBundle\Utils\Collections\SortedCollection

<?php
namespace DelfosBundle\Utils\Collections;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Array collection with elements alwais in order
 */
class SortedCollection extends ArrayCollection{
    /*** more code ***/
}

But I receive this error now:

Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionException: You must configure a PersistentCollection directory. See docs for details.

/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionException.php:38
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php:73
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/PersistentCollection/AbstractPersistentCollectionFactory.php:50
/var/www/html/delfos2/var/cache/test/doctrine/odm/mongodb/Hydrators/DelfosBundleDocumentSectionHydrator.php:118
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php:456
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php:2690
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:643
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:508
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentRepository.php:186
/var/www/html/delfos2/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentRepository.php:221
/var/www/html/delfos2/tests/DelfosBundle/Document/SectionTest.php:32
/var/www/html/delfos2/tests/DelfosBundle/Document/SectionTest.php:32

This are the versions I am using

$ php bin/console -V
Symfony version 2.8.6 - app/dev/debug

$ composer show -i
ci/restclientbundle                  2.0.0              Provides REST request methods. Mapper bundle for php internal curl library
doctrine/annotations                 v1.2.7             Docblock Annotations Parser
doctrine/cache                       v1.6.0             Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.3.0             Collections Abstraction library
doctrine/common                      v2.6.1             Common Library for Doctrine projects
doctrine/dbal                        v2.5.4             Database Abstraction Layer
doctrine/doctrine-bundle             1.6.2              Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.3.0              Symfony Bundle for Doctrine Cache
doctrine/inflector                   v1.1.0             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                1.0.5              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/mongodb                     1.3.0              Doctrine MongoDB Abstraction Layer
doctrine/mongodb-odm                 dev-master 7c0d06e Doctrine MongoDB Object Document Mapper
doctrine/mongodb-odm-bundle          dev-master e9d6ce2 Symfony2 Doctrine MongoDB Bundle
doctrine/orm                         v2.5.4             Object-Relational-Mapper for PHP
friendsofsymfony/user-bundle         dev-master d1fccc6 Symfony FOSUserBundle
incenteev/composer-parameter-handler v2.1.2             Composer script handling your ignored parameter file
ircmaxell/password-compat            v1.0.4             A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash
jdorn/sql-formatter                  v1.2.17            a PHP SQL highlighting library
kriswallsmith/assetic                v1.3.2             Asset Management for PHP
monolog/monolog                      1.19.0             Sends your logs to files, sockets, inboxes, databases and various web services
paragonie/random_compat              v2.0.2             PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
psr/log                              1.0.0              Common interface for logging libraries
sensio/distribution-bundle           v5.0.6             Base bundle for Symfony Distributions
sensio/framework-extra-bundle        v3.0.16            This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle              v3.0.6             This bundle generates code for you
sensiolabs/security-checker          v3.0.2             A security checker for your composer.lock
swiftmailer/swiftmailer              v5.4.2             Swiftmailer, free feature-rich PHP mailer
symfony/assetic-bundle               v2.8.0             Integrates Assetic into Symfony2
symfony/console                      v3.0.6             Symfony Console Component
symfony/monolog-bundle               2.11.1             Symfony MonologBundle
symfony/phpunit-bridge               v2.8.6             Symfony PHPUnit Bridge
symfony/polyfill-apcu                v1.2.0             Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu            v1.2.0             Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring            v1.2.0             Symfony polyfill for the Mbstring extension
symfony/polyfill-php54               v1.2.0             Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55               v1.2.0             Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56               v1.2.0             Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70               v1.2.0             Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util                v1.2.0             Symfony utilities for portability of PHP codes
symfony/process                      v3.0.6             Symfony Process Component
symfony/security-acl                 v3.0.0             Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle           v2.3.11            Symfony SwiftmailerBundle
symfony/symfony                      v2.8.6             The Symfony PHP framework
symfony/var-dumper                   v3.0.6             Symfony mechanism for exploring and dumping PHP variables
twig/twig                            v1.24.0            Twig, the flexible, fast, and secure template language for PHP
malarzm commented 8 years ago

You need to change your doctrine/mongodb-odm-bundle version to dev/poc-collections so eveyrthing will be configured properly (i.e. directory to which generated classes are written).

I am trying to use custom collection classes (#1219) as I've seen this is a new feature for 1.1 and It's really very awesome.

Really glad to hear that, thanks!

malarzm commented 8 years ago

Offhand I should formalize bundle's PR more today, I see it's still pointing to my ODM fork as I prepared it before merging collections into main master branch.

davidrojo commented 8 years ago

Thanks for the comment, I've changed the composer.json for mongodb-odm-bundle to dev-poc-collections but when I run composer update I receive this error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for doctrine/mongodb-odm-bundle dev-poc-collections -> satisfiable by doctrine/mongodb-odm-bundle[dev-poc-collections].
    - doctrine/mongodb-odm-bundle dev-poc-collections requires doctrine/mongodb-odm dev-poc-collections as 1.0.x-dev -> no matching package found.

I am not very familiar with composer still, so i don't know which change should I do to get this running. Thank you.

malarzm commented 8 years ago

Gimme a moment, I'll straight out bundle now, I'll ping you here when it's done :)

davidrojo commented 8 years ago

Thanks :)

malarzm commented 8 years ago

@davidrojo I've updated the bundle, can you try installing deps once again?

davidrojo commented 8 years ago

Yes, It's now working. Thank you very much.

I will add you in the agreements section of my university project :)

josefsabl commented 6 years ago

Hello, it is 2018 and I am still getting this error on v 1.2.5 :) Albeit with my custom collection.

Steveb-p commented 6 years ago

@josefsabl what error are you getting exactly?

Please provide some details or at the very least show your dependencies.

jmikola commented 6 years ago

Since this issue was closed and resolved, I would strongly suggest opening a new issue to fully describe the outstanding problem. Of course, you can link back to this issue for context. By doing so, you'll ensure the new issue gets proper attention and can be triaged appropriately.

nikhipandeysendinblue commented 1 year ago

You must configure a hydrator directory. See docs for details. i am getting this error anyone help ?