Reputation: 47
I'm using some domain with m:n relations in an Extbase TYPO3-Extension and want to get an output grouped by an attribute from a m:n-relation child, ideally respecting including entries having several relations.
Let's say I have Books and Categories. Books have some "title" and a "memberOfCategories" attribute, Categories have some "name" and a "areBooks" attribute. The general m:n thing (using some mn-table and the necessary fields in TCA and so on) works fine.
Using fluid, output of all categories of a book works fine, as well as all books having a certain category and so on.
But I need (in the book view / action context!) some output like that (including "duplicate" output of books belonging to more than one category):
Category A
Book A
Book B
Category B
Book A
Book C
(No Category)
Book D
Book E
I tried using the f:groupedFor
ViewHelper, but that does not work as I want. Grouping by the child attribute (category.name) does not work as desired:
<f:groupedFor each="{books}" as="booksOfThisCat" groupBy="memberOfCategories.name" groupKey="memberOfCategories.name">
<h3>{memberOfCategories.name} (should be category name)</h3>
<f:for each="{booksOfThisCat}" as="book">
<li>{book.title}</li>
</f:for>
</f:groupedFor>
My first try was grouping just by memberOfCategories
- but that leads to a different and unuseful result as well, because memberOfCategories only references to the "number" / set of relations, so the grouping is rubbish.
Sure that would all be very easy if I worked within an action of Categories, there it would just be a simple for each category { for each areBooks }
thing, but I need that output in an action / view regarding books.
I'm pretty much sure I'm just too dumb or blind - and may have confused some readers with the slightly pidgeon English ;-), anyhow, it would be great if anybody had some hint for that. Found some similar question regarding grouping by dates, solved with a custom view helper, but I thought there might / should be an easier solution.
Upvotes: 0
Views: 741
Reputation: 47
Oh oh - now I just got behind it on myself, it's just that simple: Add / inject the category-Repository to my books-controller and assign its desired output (e.g. findall) to my action / view and everything is fine es it already was under the category-controller.
Upvotes: 0