This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

oskar.villani40843
oskar.villani40843

Hi,

I'm trying to set up a relation where an item belongs to a subgroup and the subgroup belongs to a maingroup. (generally speaking)

My objective is to display a list in backend where each item is displayed with its subgroup (this works with a belongsTo relation already) and the maingroup row by row. Should look like this:

| maingroup 1 | subgroup 1a | item aaa |
| maingroup 1 | subgroup 1b | item bbb |
| maingroup 2 | subgroup 2a | item ccc |
| maingroup 3 | subgroup 3a | item ddd |

and so on. Any ideas how to implement this?

[edit: of course the subgroup belongsTo maingroup relations works fine too already ]

Thanks in advance
Oskar

Last updated

daftspunky
daftspunky

You would need three models, Item, Subgroup and Maingroup. Then set up the relationship types accordingly. Then you can include list columns against the Maingroup model.

name:
  label: MainGroup Name

subgroup[name]:
  label: Subgroup Name

subgroup[item][name]:
  label: Item name

There will most certainly be some performance implications from this, so you should extend the list query to include the relationships as an eager load

$query->with('subgroup.item');

Hope this helps

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.