Feature: Lifecycle Callbacks #60

Open
DavidBadura opened this Issue Feb 20, 2013 · 0 comments

Comments

Projects
None yet
1 participant

It would be very useful to have DoctrineORM Lifecycle Callbacks in CouchdbODM, too.
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-callbacks

Usecase:
If you save an object and after that you change the mapping information, for example add a embedOne field, then the new field is null if you load the object again. This is logical, but sometimes you want to set default values.


class Foo 
{

  /**
   * @CouchDB\EmbedOne()
   */
  private $bar;

  public function __construct()
  {
    $this->bar = new Bar();
  }

  /** @PostLoad */
  public function updateDefaultValues()
  {
    if($this->bar === null) {
      $this->bar = new Bar();
    }
  }

}

class Bar
{
  // ...
}

The same problem we have with EmbedMany fields. We save an ArrayCollection and we get back either null or an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment