October: Backend Nested Relations

Created on 26 Apr 2016  路  13Comments  路  Source: octobercms/october

I'm looking for a tuto/example on how to build nested relations on backend.
I'm developing a plugin as a learning experience (https://github.com/ebhoren/octobercms-nested-relations) and i need to create nested relations.

Actual result

  1. Select the Hockey Glove product.
  2. Go to Layers tab.
  3. Click Finger layer. A popup form should appear.

As you can see, each layer can be available in 6 various colors. Each colors is displayed in a checkbox.

Expected result

The colors relations look good if we have a small number of colors. It would be better if we could add|remove color associated with this layer with a complete October back-end list view.

I usually do this by creating a partial that render relation using:
relationRender('layers') ?> in a controller.

Which looks like this:
alt text
alt text

Anyone know how to do this kind of relations inside another relations?
Thanks

High Question

Most helpful comment

All 13 comments

I also have a question relating to nested relations. Is it possible to have a nested partial within a partial relation?

I tried it and what its giving me is the primary nested partial's fields and columns: Screenshot below

Relation types:
Show->hasMany(Seasons) | Seasons->hasMany(Episodes) | Episodes->belongsTo(Season)

Or do u have any solutions on how i should implement this?

I'm also stuck on this one. At the least it would be good to be able to link to another controller in an embedded list (using a partial to display a relation list, in which records have other hasMany relations). If we can do this and change the selection behavior from showing a form (which will not currently work as the relation in the form belongs to the current controllers models relation, not the current model), to a link with the records id, then we can simply link to plugin/othercontroller/update/:id and work around it.

Any tips on how to do this?

Any comeback on this?
Can someone take a deeper look into this? I'm stuck on this problem for months.
Any help would be really appreciated.
Thanks

@ebhoren I dont know if it would help but the solution i came up for my plugin is that I had let the primary controller (shows) use the seasons and the episodes as partials (so they get their individual tabs)

and to gather the raltion within the relation for example a dropdown relation within the relation. I went into the nested relation's model thats requesting another model's relation and did this:

`

public function getSeasonOptions()
{
    return Season::where('show_id', Request::segment(6))->lists('title', 'id');
}

`

i used Request::segment() to get a specific relation based on the relation to the show. IT's the only solution i have come up with and it works. The segment finds the id within the update url ( so this can only be done within updates.)

@Teranode could you provide more code about your solution? I'm struggling to understand your solution.
Thanks

is there any progress about this issue?

@chesterx No progress at all.

Related issue #2567

The Relation Controller support does not appear to support nesting. We will look at writing a tutorial on how to address this soon.

Just a heads up, nested relations probably won't be supported. Behaviors are designed to be helpful in speeding up development, not as the answer to every possible implementation.

We are working on a series of screencast tutorials that describe this in more detail. See the following repo for more details: https://github.com/daftspunk/oc-formist-plugin

Thanks @abstractFlo for providing the basis for this plugin.

This series open my mind with october. Thats so awesome, after understand the technology behind october magic :D

The Beyond Behaviors series was helpful - just wondering if you able to give a quick example or point in the direction of how we can tackle having a belongToMany or morphToMany relation in a popup?

I see we can build out the list the same was as outlined in the series, however - how do we use add or link existing records which would open in another popup, with a list of available, selectable records.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings