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

Joerg Schoppet joerg at schoppet.de
Fri Oct 9 15:35:40 CEST 2009


Hi,

success-message was to early :-(

I'm totally stuck.

If I do it the way mentioned below, the positions are correctly updated 
with the invoice, but not the other way round. e.g. the imports-fields 
is not updated with "3", if I add the invoice to three importPositions.

If I manually update the invoice-record with "3" for imports I receive 
an internal server-error, when trying to fetch it within my 
extbase-extensions (perhaps a circle reference).

Can somebody give me a hint of how I can solve this problem?

My use-case is:
- Positions are created first
- Afterwards I want to select, which positions should be grouped 
"within" an invoice
- I must know, if a position is already assigned to an invoice


Joerg



Joerg Schoppet schrieb:
> 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