[TYPO3-mvc] repository->add => persistenceManager->persistAll => repository->findBy

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jul 12 10:52:07 CEST 2010


Hey Daniel,

>> I'm kind of confused by your domain structure and naming, so I'm not
>> sure where the problem could come from. As it seems, your cart can
>> only have one product? If so, then the class name of the model feels
>> odd as it implicates plural - or might this be misspelled and be the
>> error?
>
> Ok, I slowly start to see why we need good names :)
> products is the model that I use in list view
> product is the model that I use in single view
>
> They both map the same table, but the first one (products) has just 2
> properties - name and author.
> and Product on the other side has around 20-30 properties.

Just curious - did you have memory issues to do this, or what was the 
reason for this decision? I think I remember some older post of you (or 
somebody else) where has been asked if one can drop unneeded properties 
in queries so that they don't get loaded mapped.


>> If you on the other hand allow multiple products (which I assume) in
>> your cart, then you don't need a "product" property, but a "products"
>> (plural) and make it a objectStorage:
>>
>> /**
>> * The products currently in the cart
>> * @var
>> Tx_Extbase_Persistence_ObjectStorage<Tx_BwShop_Domain_Model_Product>
>> */
>> protected $products;
>>
>>
>> Maybe there is the error?
>
> My cart stores the date and the product_id. The product id is not an
> mm_relation, but 1:1 relation.

So, the "cart" with the $products property is actually a cartItem then, 
right?

...
> and I use the same code to get my products in addToCartAction.
> The only difference is that the AddToCartAction function is called in
> the context of an ajax call(using page type for this).
>
> As I said after the ajax call the right data is saved in the cart, but
> no mapping for the inserted row is made.

I just had a look at the code in your initial posting:

> $sessionId = $this->cartModel->getUserSessionId();
> $this->cartModel->setSessionId($sessionId);

OT: I think it's not nice to have the cartModel determine the 
userSessionId and then set it for the same model. From my understandings 
of your domain, fetching the userSession is in my eyes out of the domain 
of the cartModel - I'd rather move that to a service.

> $this->cartModel->setProduct($this->getParametersSafely('product_id'));

I think here is your problem. What does $this->getParametersSafely() 
return? Does it return the correct object, or just the UID? I it's just 
the UID, which is the issue in this case.
After persistence, your cartModel will NOT be created from scratch 
again, as it's still in the identityMap of the persistenceManager. So 
the repository will always return the object from the identityMap.

To solve this, you can either assign the product to the model (which is 
the cleanest solution) or delete the new cartModel from the identityMap 
before you fetch it again from the repository.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list