How to list entities and sort them by delta? I have a &quot;stations&quot; and &quot;railways&quot; node types and a custom &quot;notification&quot; entity type.
In &quot;railways&quot; node type I have an entity reference field (&quot;field_stations&quot;) where I can select &quot;stations&quot; nodes which is good.
In &quot;notification&quot; entity type I have an entity reference field where I can select related stations. (entity reference to &quot;stations&quot; nodes)
I would like to create a view to list &quot;stations&quot; nodes with grouping and sorting. I would like to group them by &quot;railways&quot; and sort them by delta (&quot;field_stations&quot;).
I tried it but I could not get the right order and get a lot of duplications. I have tried views_order_by_delta module as well with no luck.
Do you have any recommendations?
I think you're overcomplicating things here. From my reading, you really should be creating your view to:
Show content of type: Railway
This will be your &quot;grouping&quot;. You don't want to using the Views grouping option here - that option is more useful when you want to group the result content by a field on each result, i.e. if your stations node type had a reference to Railways.
Fields to Display: Title, field_stations (or, preferable imo, configure a view mode for the Railway node that displays the fields you want to show).
Since we have a view of Railways, your results are naturally &quot;grouped&quot; by Railway. If you just display the stations field from the railway, you'll get the stations listed in the order on the field (its delta).
(optional) Contextual Filter: field_stations
I'm not sure if you actually need this from your description. You can configure a contextual filter for the field_stations field to allow you to show only the Railways (and their stations) if a Railway references a station you pass as an argument.