简体   繁体   中英

Typo3 Extbase: findByParent

I have an aggregate root object in my extbase Extension called "article" that has several child objects "product" (1:n) assigned to it. How can i findByArticle in the productRepository (so findByParent in child repo). I cannot do it the normal way, getting the child records of my desired parent object, because i need load the product items by ajax call and need to set offset, limit, and different sorting on the request. (This is not possible if i just get the children of article)

thanks for the help

I think you will have to implement an own function in your repository.

An overview of the possibilities can be found here: http://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html

If you can't use the normal findByArticleId() you have to use a custom method in your (child) repository:

Something like:

public function findByArticleId($acticleId){
    $query = $this->createQuery();
    $query->matching(
        $query->logicalAnd(
            $query->equals('articleId', $acticleId ),
            $query->equals('something', 'else')
        )
    );
    $query->setOffset(10);
    $query->setLimit(20);
    return $query->execute();
}

As you can see you are able to set the limit and the offset or get what ever you want from the repository.

Details can be found here: http://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html (thanks Max)

If you have a ProductRepository and you want can access the products through anything else than an Article object, then your Article is not an aggregate root .

I would recommend implementing this logic in the Article class. It should hold a reference to an ObjectStorage object containing the products. It should be possible to get a limited number of products with an offset from that storage. You already have the article ID apparently, so you can easily find your article and its products. For performance reasons, the reference from the Article to its products should have the annotation @lazy (TYPO3 8.7) resp. @TYPO3\\CMS\\Extbase\\Annotation\\ORM\\Lazy (TYPO3 9.5).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM