This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
When I was busy with pivot tables I encountered an issue that linked lists wouldn't display and I did my best to figure out how to resolve that. Of course the solution is very simple, but if you don't know how, it isn't that simple ;-)
First of all, you have your relation set up in your model
public $belongsToMany = ['children' => ['\Tschallacka\ParentalManager\Models\Child',
'key' =>'parent_id',
'otherKey'=>'child_id',
'table' => 'children_to_parents',
'order' => 'sortorder',
'pivot'=>'sortorder',
'timestamps'=>'true']];
with timestamp columns and sortorder column added to the pivot table.
Then to display the sortorder in the relationRender we define the following rules in a file we call columnspivot.yaml
columns:
name:
label: child name
searchable: true
span: left
sorter:
label: Priority
select: rich_block_to_page.sortorder
sortable: true
pivot[sortorder]:
label: sortorder
invisible: true
Then we also make a columns.yaml
with the following content
columns:
name:
label: child name
searchable: true
span: left
It's important that the columns.yaml contains no pivot references at all.
Then in your config_relation.yaml you define your relation manager like this:
children:
label: Happy kids
view:
# The reference to the PIVOT list definition. This is used for the relationRender() display.
list: $/Tschallacka/Familymanager/Models/Child/columnspivot.yaml
toolbarButtons: create|delete|link|unlink
# I like sorting my list columns ;-) as a bonus you're supposed to define it here.
defaultSort:
column: sorter
direction: asc
manage:
# Displaying the create/update form
form: $/ExitControl/RichIndexPageManager/Models/RichBlock/fieldspivot.yaml
# The list that's used for the link button. Since these are only unlinked items
# being displayed there without any relation to the object it cannot contain
# any pivot data reference as the query would fail.
list: $/ExitControl/RichIndexPageManager/Models/RichBlock/columns.yaml
recordsPerPage: 20
Last updated
You may still run into dificulties if you use NestedTree Trait on the child model. Still not figured how to use both...
1-2 of 2