[TYPO3-mvc] Respect storage page ignored on object properties
Jochen Rau
jochen.rau at typoplanet.de
Mon May 31 15:06:31 CEST 2010
Hi Thomas.
On 30.05.10 17:47, Thomas "Thasmo" Deinhamer wrote:
> Am 29.05.2010 09:57, schrieb Jochen Rau:
>> Unfortunately, the patch will not solve your problem, because I do not
>> intent to delete the line
>>
>> $query->getQuerySettings()->setRespectStoragePage(FALSE);
>>
>> as the behavior you encountered is not a bug.
>
> Hello Jochen,
>
> what's the main reason for this then? I think Sebastian already told me
> the reasons, but I didn't get the point.
First of all, the state of domain objects and the state of aggregates
has to be free of side effects. In other words: The domain model must
not depend on the environment. Adding, removing and manipulating objects
must be performed via the API of the domain model (eg.
$product->addCategory($category)).
In your domain model, you add and remove products assigned to a
particular category by selecting the PID of the products. But a "Page"
(and its ID) is clearly not part of your domain. A product or a category
itself has no clue about a page tree.
Let's assume you have a category holding references to some products
(the products are "stored inside" the category). It must be very
confusing if somebody moves a product to another PID and it disappears
magically from the category without doing a
$category->removeProduct($product) explicitly.
You might argue, that Repositories *are* restricted to search only on
the storagePids. So why doesn't this apply to related objects (like
products), too? The objects/aggregates you fetch from a repository via
its find*() methods are a selection of the "whole world" (in most
cases). That's what repositories are made for. If you invoke
$personRepository->findAll(), you get get back only a selection of all
possible persons. But the person "Jochen Rau" is always the same
(because I hopefully have an identity). The content of the backpack of
"Jochen Rau" does not change because he changes the bus (besides of
pickpockets ;-)).
Ok, but how to solve your problem? IMO you should alter your domain
model from
class Category {
var $products
}
to
class Product {
var $categories
}
as a Category is more of a ValueObject that an Entity. The next step
depends upon the quantity of products you have to manage. I always try
to put the logic to fetch the necessary subset of products in the
controller using a find*() method of the appropriate Repository.
For your case a $query->intersect('categories' $categories) would be
handy but it should also work by concatenating
$query->contains('categories', $category) with $query->logicalOr().
Regards
Jochen
More information about the TYPO3-project-typo3v4mvc
mailing list