[TYPO3-50-general] Persistence: edit/remove elements

Robert Lemke robert at typo3.org
Tue Dec 23 09:51:20 CET 2008


Hi all,

Am 22.12.2008 um 21:11 schrieb Christoph Blömer:

>>> is there a way to edit or remove objects already?
>>>
>>> thx :-).
>>>
>> yes, just edit or remove them ;-) Every change in an object already
>> persisted (is in a repository) will be recognized by the framework.  
>> To
>> remove an object, just destroy it, for example with unset($object);
>>
>>
> Also Karsten wrote me, that you can use:
> $myRepository->remove($object);
>
> But i didn't tried it yet.

In general we have based the strategies for persistence on the concepts
of Domain Driven Design. It's quite simple:

If an object is

   - tagged as an @entity or @valueobject and
   - is directly or indirectly connected to a repository

it is persisted.

Consider these examples:

$customerRepository->add($customer); // customer will be persisted

$customer->addContract($contract);   // contract will also be persisted
$contract->addDetail($detail);       // detail will also be persisted

$contract->removeDetail($detail);    // detail will be deleted
unset($customer);                    // customer + contract will still  
be persisted
                                      // because they are still  
connected to the
                                      // $customerRepository

$customerRepository->remove($customer);  // Deletes the $customer

.....

                                      // Retrieves one customer
                                      // Note that findOneBy* is only  
planned, not yet implemented
$otherCustomer = $customerRepository->findOneByLastName('Foo');
$otherCustomer->setLastName('Bar');  // Changes the lastname - will  
automatically be persisted

Note that persistence of additions / changes takes place at the end of  
the
script run. You can force changes to be persisted by calling the  
persistAll()
method of the Persistence Manager.

Cheers,
robert




More information about the TYPO3-project-5_0-general mailing list