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

Joerg Schoppet joerg at schoppet.de
Sun Oct 25 15:38:29 CET 2009


Hi,

still not working.

I, once again, try to sum up everything:

I have an invoice with several positions.

Invoice:
Tx_MyExample_Domain_Model_Invoice:
         'positions' => array(
             'exclude' => 0,
             'label' => 'Positions',
             'config'  => array(
                 'type' => 'inline',
                 'foreign_table' => 'tx_myexample_domain_model_position',
                 'foreign_class' => 'Tx_myexample_Domain_Model_position',
                 'foreign_field' => 'invoice',
                 'size' => 10,
                 'minitems' => 0,
                 'maxitems' => 9999,
                 'autoSizeMax' => 30,

Tx_MyExample_Domain_Model_Position:
         'invoice' => array(
             'exclude' => 0,
             'label' => 'Invoice',
             'config' => array(
                 'type' => 'select',
                 'foreign_class' => 'Tx_MyExample_Domain_Model_Invoice',
                 'foreign_table' => 'tx_MyExample_domain_model_invoice',
                 'size' => 1,
                 'minitems' => 0,
                 'maxitems' => 1,


My use-case includes, that first positions are created without a 
reference to an invoice. Then I select multiple positions and let an 
invoice beeing created.

And here is the problem.

Within my InvoiceController I have the following createAction:
     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);
                 $this->positionRepository->add($position);
                 $invoice->addPosition($position);
             }

         }

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


But now I create the following Extbase-Exception:
Tx_Extbase_Persistence_Exception_CleanStateNotMemorized
The clean state of the object "Tx_MyExample_Domain_Model_Invoice" has 
not been memorized before asking _isDirty().


So, IMHO, I have to create an invoice, save it to have an uid, and then 
do this stuff with positions.

Or not?


Joerg


More information about the TYPO3-project-typo3v4mvc mailing list