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

Jochen Rau jochen.rau at typoplanet.de
Wed Oct 28 09:53:53 CET 2009


Hi Joerg.

Joerg Schoppet wrote:
> 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',

might be
'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);
The next line is not necessary. The position is already handled by the 
repository.
> $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));
> }

Do both of your classes you extend Tx_Extbase_DomainObject_AbstractEntity?

Regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list