Hi Roy,

See
http://docs.doctrine-project.org/en/latest/reference/working-with-objects.html#persisting-entities

Any object that is created and that is not yet known to the ObjectManager
is "UNMANAGED" ("DETACHED" if it has an identifier)
Any object that was fetched from the ObjectManager is "MANAGED"
Any object that is persisted via the ObjectManager is "NEW"
Any object that is removed via the ObjectManager is "REMOVED"
Any object that is cleared from the ObjectManager is "DETACHED"

Flushing causes "REMOVED" instances to become "UNMANAGED"

See
https://github.com/doctrine/doctrine2/blob/f197a9c9f140a06f399fc05d7149220d04eb3a56/lib/Doctrine/ORM/UnitOfWork.php#L63-L85for
more details. You can lookup usages of those constants within the
UnitOfWork to have a better understanding of what is going on.

Cheers,


Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 9 March 2014 20:47, Roy Epperson <[email protected]> wrote:

> Herman,
> Just to clarify my understanding, any I create a new instance of a class
> it needs to be persist($anInstance_of_a_class). But any time it is
> retrieved via and $enitityManager->find*() or loaded when being loaded by
> the found object, it is not need?
>
> If you add another instance of a class to an already managed is it
> automatically included it the UnitOfWork or do you have explicitly
> persist($it)?
>
> Roy
> On Mar 9, 2014 12:29 PM, "Herman Peeren" <[email protected]> wrote:
>
>> On Sunday, 9 March 2014 20:13:38 UTC+1, Parsifal wrote:
>>>
>>> Sorry i  got confused.
>>> So there is no need to persist at all and just flush outside foreach
>>> when foreach is finished? I tought before every flush i need to use
>>> persist, so please clarify what is the purpose of persist if i don't need
>>> to use it in this case at all?
>>>
>>
>> Persist( ) is a bit confusing name for that method. Maybe it might better
>> have been called manage( ), but that name is not very clear too. But what
>> you do with persist( ) is making an entity managed, that is: all updates to
>> it will be taken into account at the next flush( ).  When you retrieve
>> Entities via the Repository, using find( ), findBy( ) etc, they are
>> allready managed. So: no need to call persist( ) for them.
>>
>> --
>> 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 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 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