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

damianlewis
damianlewis

I have the following models:

  • Category
  • Lookbook
  • Item

With these relationships:

  • Category hasMany Lookbooks
  • Lookbook belongsTo Category
  • Lookbook belongsToMany Items
  • Items belongsToMany Lookbooks

I'm able to access these relationships in the backend forms via the relation behaviour controller modifier, so I can see the list of lookbooks for a category and I can see the list of items for a lookbook. If I click on an item from a lookbook, I can edit it in the relation manager popup but if I click on a lookbook from a category I get an error in the relation manager popup. The popup displays the raw HTML for the popup followed by the message "Relation behaviour does not contain a definition for 'items'."

It seems that the problem for categories is caused by the nested item relation in the lookbook.

Is it possible to access a relation via the relation manager for a relation that has it's own relations, i.e. a nested relation? (Hope that makes sense)

KurtJensen
KurtJensen

I think in your case "Lookbook" hasMany "Items" instead of "Lookbook" belongsToMany "Items".

When struggling with relations I like to review the code in the Test plugin.

See: https://github.com/daftspunk/oc-test-plugin

It has contains examples of relations and the form options you can use.

damianlewis
damianlewis

Thanks KurtJensen, the examples in the test plugin are really useful. However I can't see any relationship in the source code for the countries test which shows a "Has many through relationship". I'm not sure if this is the type of relationship I need to create.

I tried your suggestion of using a hasMany relationship between Lookbooks and Items but I still get the same problem.

Just to reiterate the problem I'm having, here's how I've setup the relationships between my models.

  • A Category can have many Lookbooks and each Lookbook belongs to one Category (a one-to-many relationship).
  • A Lookbook can have many Items and an Item can belong to many Lookbooks (a many-to-many relationship using an items_lookbooks joining table).

In the backend I have a sidemenu item for categories and lookbooks. Using the relation manager I can:

  • Render a list of Lookbooks for a selected Category in the categories form.
  • Render a list of Items for a selected Lookbook in the lookbooks form.

The problem I'm having is with the rendered list of Lookbooks for a Category. Although I can see the list of Lookbooks, when I select a Lookbook or try to create a new Lookbook via the 'Create lookbook' button, the relation popup contains the raw HTML for the popup form, with a message at the end saying "Relation behaviour does not contain a definition for 'items'."

The problem only occurs when I try to create/update a Lookbook via the categories form. I have no problems creating/updating Lookbooks via the lookbooks form and have no problem creating /updating Items via the lookbooks form.

If anyone could help me out with this, it would be much appreciated.

Last updated

ad.drop
ad.drop

hello damianlewis, did you came up with a solution to this issue ? Kind regards

1-4 of 4

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