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

jcbbuller52235
jcbbuller52235

I'm having issues using the RainLab Builder plugin. I have my fields set so they can be reordered and my controller has reordering capabilities, but when I click the reorder button when accessing the custom plugin I built using RainLab Bulder, I get an error page with the folliwing:

The model must implement the NestedTree or Sortable traits. /Users/jacobbuller/Desktop/Sites/bullernotbuellercms/modules/backend/Behaviors/ReorderController.php line 225

Anyone know how to fix this issue?

Flynsarmy
Flynsarmy

The documentation shows how to implement this behaviour in your model: https://octobercms.com/docs/backend/reorder

jcbbuller52235
jcbbuller52235

Great thanks! I'll try it out and post here if I hit any snags.

jcbbuller52235
jcbbuller52235

So I added use \October\Rain\Database\Traits\Sortable; to my plugin model, but now I get the following issue. Any reason why this might be happening with RainLab Builder? My database doesn't have

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort_order' in 'order clause' (SQL: select * from jcbbuller_projects_ order by sort_order asc)

Eoler
Eoler

jcbbuller52235 said: So I added use \October\Rain\Database\Traits\Sortable; to my plugin model, but now I get the following issue. Any reason why this might be happening with RainLab Builder? My database doesn't have SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort_order' in 'order clause' (SQL: select * from jcbbuller_projects_ order by sort_order asc)

Add the sort_order field to your model's database table.

jcbbuller52235
jcbbuller52235

Sounds simple enough. Do I need to add integers into the sort_order field in the database or do they prepopulate automatically?

jcbbuller52235
jcbbuller52235

UPDATE: Got it to work. Created a sort_order integer field, set the default value to null, and everything seems to be working! So if you have this issue, do that. Thanks for the help Eoler and Flynsarmy

Last updated

Eoler
Eoler

jcbbuller52235 said: UPDATE: Got it to work. Created a sort_order integer field, set the default value to null, and everything seems to be working!

This will probably do for existing records, but to ensure valid data (inserts, etc.) you can also add the following event handler to the model class:

    public function beforeValidate()
    {
        if (empty($this->sort_order))
        {
            $this->sort_order = static::max('sort_order') + 1;
        }
    }

1-8 of 8

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