[TYPO3-mvc] Relation-Field of existing objects not updated
Joerg Schoppet
joerg at schoppet.de
Fri Oct 9 13:20:39 CEST 2009
Hi,
I don't know really why, but it is working the other way round:
Create a new Invoice and just add this Invoice to the different positions:
$invoice =
t3lib_div::makeInstance('Tx_JrCustomer_Domain_Model_Invoice');
$invoiceNumber = $this->calculateNumber(
(int)date('j'),
(int)date('n'),
(int)date('Y')
);
$invoice->setNumber($invoiceNumber);
if (isset($manuals)) {
foreach ($manuals as $manualUid) {
$manual =
$this->manualRepository->findOneByUid($manualUid);
$manual->setInvoice($invoice);
$this->manualRepository->add($manual);
}
}
if (isset($imports)) {
foreach ($imports as $importUid) {
$import =
$this->importRepository->findOneByUid($importUid);
$import->setInvoice($invoice);
$this->importRepository->add($import);
}
}
Joerg
Joerg Schoppet schrieb:
> Hi,
>
> I have the following object-"structure".
>
> Invoice
> - number
> - manuals
> - imports
>
> Manual
> - name
> - price
> - invoice
>
> Import
> - name
> - price
> - importedFrom
> - invoice
>
>
> Positions (manual and import) can be created without an invoice. Problem
> is, that when I create a new invoice and assign e.g. three Imports, then
> the field "imports" is correctly updated with "3", but the "invoice"
> fields of the Imports are not updated.
>
> Here is the code of the action:
> $invoice =
> t3lib_div::makeInstance('Tx_JrCustomer_Domain_Model_Invoice');
> $invoiceNumber = $this->calculateNumber(
> (int)date('j'),
> (int)date('n'),
> (int)date('Y')
> );
> $invoice->setNumber($invoiceNumber);
>
> if (isset($manuals)) {
>
> foreach ($manuals as $manualUid) {
> $manual =
> $this->manualRepository->findOneByUid($manualUid);
> $invoice->addManual($manual);
> }
>
> }
>
> if (isset($imports)) {
>
> foreach ($imports as $importUid) {
> $import =
> $this->importRepository->findOneByUid($importUid);
> $invoice->addImport($import);
> }
>
> }
>
>
> Have I missed something?
>
>
> Joerg
More information about the TYPO3-project-typo3v4mvc
mailing list