[TYPO3-mvc] Weird behaviour of persiting sub/child objects

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Fri Jan 29 01:10:16 CET 2010


Ah, okay - good question, where it belongs to.
I'll maybe look into this a bit the next time.

Thanks,
Thomas

Am 29.01.2010 00:34, schrieb Franz Koch:
> Hi Thomas,
>
>> this code behaves very weird:
> ...
>> The result is, that the cartItem object gets persisted
>> to the database table, but the customer property
>> is not set. It's just 0.
>>
>> If I comment in '$cartItem->setCustomer($this->customer);'
>> the customer property is set, also in the database correctly.
>>
>> Is this an intended behaviour or am I
>> maybe missing some kind of relation definition somewhere?
>
> on having a look at the blog example, there the blog object is also
> assigned to the post "by hand".
>
> $blog->add($post);
> $post->setBlog($blog);
>
> So it seems to be intended that way. What you could do to ease things up
> for you is to have the customer model is add itself to the cartItem in
> the addCartItem method:
>
> public function addCartItem(Tx_... $cartItem) {
> $this->cartItems->add($cartItem);
> $cartItem->setCustomer($this);
> }
>
> The only question is if this logic should belong to the model or the
> controller - or maybe a service
> (Tx_..._CartService::addCartItemToCustomer($cartItem, $customer)?
>


More information about the TYPO3-project-typo3v4mvc mailing list