In the documentation, there is an option to sort M:N relations using SortableRelation. For example, categories and books. The book has several categories.
If all relationships are defined in one plugin, then everything works correctly.
If I create two plugins. One plugin contains categories. The second plugin contains books. I will extend the category model with a relation to books. Subsequently, sorting books in categories using SortableRelation does not work.
What is the problem? Is there a bug in OctoberCMS?
There is one caveat with this approach at the moment. The sorting will only work on existing records since the sort_order is within the deferred binding table. We are working on a solution to this in a later version.
Could it be that in your extended example, the primary record does not exist yet?
I only sort in category update action. So the category (primary record) exists. Books (secondary record) also exist.
If I have both categories and books in one plugin. There is a sort_order field in the data that is sent when sorting.
If I have categories and books split into two plugins. The sort_order field is missing in the data sent when sorting.
If the category binding is - the book is created in the Category class (Fiestplugin\Models\Category, line 33). Then book sorting works. Data sent to the server:
If the binding is a category - the book is created as an extension of the Category model (Secondplugin\Plugin.php, line 26). Then the sorting doesnât work. The sort_order field is missing from the data:
Yes, this is how (in the test plugin) sorting works. Because all models are in one plugin. The problem occurs when Galleries is in one plugin and Event is in another plugin.
If we extend the plugin and add sessions (Gallery â Event), the sorting does not work.
The âfirstpluginâ folder is the base plugin containing the category model. The âsecondpluginâ folder is an extension plugin. Contains a model for the book. The extension code is in the file âsecondplugin/Plugin.phpâ. Model, controller and form extensions. The SortableRelation property is located directly in the âfirstmodel/model/Categoryâ model.