[TYPO3-mvc] Relation-Field of existing objects not updated

Joerg Schoppet joerg at schoppet.de
Wed Oct 28 17:43:12 CET 2009


Hi

Jochen Rau wrote:
>> 'foreign_table' => 'tx_MyExample_domain_model_invoice',
> 
> might be
> 'foreign_table' => 'tx_myexample_domain_model_invoice',
This was only a typo.

>> if (isset($positions)) {
>>
>> foreach ($positions as $positionUid) {
>> $position = $this->positionRepository->findOneByUid($positionUid);
>> $position->setInvoice($invoice);
> The next line is not necessary. The position is already handled by the 
> repository.
not working, the code looks now like that

public function createAction(Tx_MyExample_Domain_Model_Customer 
$customer, array $positions=NULL) {
$invoice = t3lib_div::makeInstance('Tx_MyExample_Domain_Model_Invoice');
$invoice->setCustomer($customer);
$invoice->setDate(new DateTime());

if (isset($positions)) {

   foreach ($positions as $positionUid) {
     $position = $this->positionRepository->findOneByUid($positionUid);
     $position->setInvoice($invoice);
     $invoice->addPosition($position);
   }

}

$this->invoiceRepository->add($invoice);
$this->flashMessages->add('The invoice ' . $invoice->getNumber() . ' was
created.');
$this->redirect('detail', 'Customer', NULL, array('customer' =>
$customer));
}


> Do both of your classes you extend Tx_Extbase_DomainObject_AbstractEntity?
Yes


I still get the error:
Tx_Extbase_Persistence_Exception_CleanStateNotMemorized
The clean state of the object "Tx_MyExample_Domain_Model_Invoice" has 
not been memorized before asking _isDirty().

I think it is, because the positions are tried to saved first and at 
this time, the invoice is not saved.


Joerg


More information about the TYPO3-project-typo3v4mvc mailing list