Marco,
The constructor is bypassed because the entity is being deserialized from json 
string, so basically what I’m trying to do is take the json data - deserialize 
it and make sure that some defaults like the object creation time get set 
before I store it in the database.

-- 
Stan Lemon


From: Marco Pivetta <[email protected]>
Reply: [email protected] <[email protected]>>
Date: September 22, 2014 at 6:40:54 PM
To: [email protected] <[email protected]>>
Subject:  Re: [doctrine-user] Related objects and event listeners  

Hi Stan,

Just to be sure: why aren't you simply setting the `created` field to a `new 
DateTime` in `__construct()` instead?

Marco Pivetta

http://twitter.com/Ocramius     

http://ocramius.github.com/

On 22 September 2014 05:21, Stan Lemon <[email protected]> wrote:
Hello,
If I have a collection of related entities on an entity, which I go to persist 
and I have an event listener with something like this:

public function prePersist(LifecycleEventArgs $args)
{
    $entity = $args->getObject();
    $entity->setCreated(new \DateTime());
}

I am getting an error when the persist cascades that the column mapped to 
$created is null.

Do I need to be doing something else to change the entity at this stage?

Thanks for your help,
Stan

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google 
Groups "doctrine-user" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/doctrine-user/BaE7sOCbGlQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to