[MODM-147] No possibility to get a json object by a working document with toArray method (inluding all the embedded documents as arrays) Created: 28/May/11  Updated: 28/May/11

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Collections
Affects Version/s: 1.0.0BETA3
Fix Version/s: None

Type: New Feature Priority: Major
Reporter: Stephan Salat Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 1
Labels: None
Environment:

Irrelevant



 Description   

Description of the problem here:

http://stackoverflow.com/questions/6155189/doctrine-odm-mongodb-get-a-complete-array-of-an-object

Problem with the unincisive toArray() method.






[MODM-173] Change the name of the collection dynamic Created: 27/Jun/13  Updated: 27/Jun/13

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Collections
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Daniel Gafitescu Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I have to create collection for users per each day they register so if I have 5 users and 2 register on 2013-03-02 and 3 have register on 2013-03-03 I will have 2 collections

The user is declare in a YML file with no collection specified

In the project I do an import via CLI something like this

foreach($arUsers as $key => $arUser)
{

    $collection_name = 'day_' . $arUser['date'];


    $user = new User();

    /* Change the collection name to be dynamic  */
    $OdmMetaData = $documentManager->getClassMetaData(get_class($user));

    $OdmMetaData->setCollection($collection_name);

    $user->setUserId($arUser['user_id']);
    $user->setEmail($arUser['email']);

    // ....

    $this->getDocumentManager()->persist($user);
    $this->getDocumentManager()->flush();
    
    // should save the user to `'day_' . $arUser['date']`
}

Problem is that when I look in the mongoDB I see only one collection with name "day_2013-03-03" which is the last date , if I set the

$documentManager->flush();

after the foreach end statement which I should it save all in the first collection "03-02".



 Comments   
Comment by Marco Pivetta [ 27/Jun/13 ]

I personally don't think that's an use case to be handled in the ODM.

The problem is that class metadata properties are not constantly accessed, but instead cached locally in various components for performance reasons.

A fix for this would be to explicitly deny modification of metadata after it was returned by the metadata factory (after "onLoadMetadata" events).

Comment by Daniel Gafitescu [ 27/Jun/13 ]

Reinitialize the DoctrineManager at every group of document did the trick but it's just not beautiful code.
In a perfect world it would be nice to have a method setCollectionName on a object. But then again Doctrine is a open source project and all that work on the project are doing this on their own time and I thank you for that.





Generated at Thu Apr 24 10:09:48 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.