Skip to content

Instantly share code, notes, and snippets.

@gquemener
Created May 21, 2014 13:59
Show Gist options
  • Save gquemener/5c87598b956e0d0b4330 to your computer and use it in GitHub Desktop.
Save gquemener/5c87598b956e0d0b4330 to your computer and use it in GitHub Desktop.
<?php
/**
* @ORM/Entity
*/
class Product
{
/**
* @OneToMany(targetEntity="Price", mappedBy="product", cascade={"refresh"})
*/
public $prices;
/**
* @OneToMany(targetEntity="Color", mappedBy="product", cascade={"refresh"}, fetch="EAGER")
*/
public $colors;
}
$product = //fetch a product from db through doctrine and hydrate it
$em->refresh($product); // $product->prices is empty
// because the BasicEmptyPersister unwrap the PersistentCollection (thus not initialize it)
// and refresh each elements (which it doesn't have, because it was not initialized)
// $product->colors is correctly refreshed and contains same colors than in DB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment