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

Jochen Rau jochen.rau at typoplanet.de
Fri Oct 23 10:29:34 CEST 2009


Hi Joerg.

Sorry for replying late.

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

>> 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);
>> }
>>
>> }

Now the following line is missing:

$invoice->addManual($manual);

You have to add (at least) the manuals and imports to the invoice. If 
you configured the relation as 1:n with foreign key reference (property 
"invoice" of manual holds the uid of ) you are done. Have a look at the 
blog_example how this is done (you have to specify "foreign_field" => 
"invoice").

regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list