2

I have a problem with a PersistentCollection.

I have an Object User (herited of FOSUserbundle user class) who have an EmdebedDocument Seance. The Seance have an Array of Event. My Seance Class:

/**
* @MongoDB\EmbeddedDocument
*/
class Seance
{
/**
 * @MongoDB\Id
 */
protected $id;

/**
 * @MongoDB\EmbedMany(targetDocument="Event")
 */
protected $dispos ;

/**
 * @MongoDB\Field(type="string")
 */
protected $rayonDeplacement;

/**
 * @MongoDB\Field(type="string")
 */
protected $lieu;

/**
 * @MongoDB\Field(type="string")
 */
protected $prix;

/**
 * @MongoDB\Field(type="string")
 */
protected $nbPersonne;

And my class Event

/**
* @MongoDB\EmbeddedDocument
*/
class Event extends BaseEvent
{
/**
 * @var integer
 * @MongoDB\Id
 */
protected $id;

/**
 * @var \DateTime
 * @MongoDB\Field(type="date")
 * @Assert\NotNull()
 */
protected $startDate;
/**
 * @var \DateTime
 * @MongoDB\Field(type="date")
 * @Assert\NotNull()
 */
protected $endDate;

I give the event from user with:

$user->getSeance()->getDispos()

This function returns a empty PersistentCollection while they are events in database.

When dump the return of getDispos() method I have: dump of result getDispos() method

I dont't understant why I have mongoData field with my data but arrayCollection empty.

Thank you for yout help.

1 Answer 1

5

PersistentCollection is initialized lazily - for performance reasons, the data from database is held in mongoData. The collection is initialized during the first time you need some data from it (or try to modify it) - then the data held in mongoData is hydrated into your embedded documents and that is added to decorated coll. All this is happening transparently to you, just try using your collection instead of dumping it.

Sign up to request clarification or add additional context in comments.

3 Comments

Hello Thank you for your answer. The problem that the document return is null hydrated with null value.
I'm not sure how that could happen, could you please try checking if $user->getSeance()->getDispos()->first() yields correct document?
Okey it's resolve I don't understand why the problem is resolve. Thank you for your help !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.