[TYPO3-mvc] Where to put automatic value calculation

Jochen Rau jochen.rau at typoplanet.de
Tue Dec 8 12:12:10 CET 2009


Hi Steffen.

schrieb Steffen Ritter:
> Steffen Ritter schrieb:
>> Hey list,
>> I wanna set some field of an object automatically/autogenerated when
>> creating an new object, things like a serial or an password, sth. like
>> this... how do i do best?

> OK,
> the storage backend knows about the "new object" status and implements
> the isNew() functionality.

Did you mean the persistence backend? The storage backend is not aware 
of the object status. It should only translate the query into something 
useful for the database/SOAP client/xml file ....

> I added an Method _onFirstPersist to the ObjectsInterface which is
> called by the StorageBackend in persistObject if isNew($object) returns
> true.
>
> Patch may be found issue tracker soon.

Thanks for the patch. We definitely have to provide a clean way to 
control the overall life cycle of an object (and its properties). But 
that is the big scope ;-). Let's focus on your problem.

Your proposed solution introduces a template method _onFirstPersist() 
which has to be implemented inside a Domain Object. This will mix up 
domain logic with the way the domain object is persisted.

I would prefer to overwrite the add() method of the Peristence 
Repository and call a 
Tx_MyExt_Domain_Service_InvoiceNumberProvider::getInvoiceNumber().

Regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list