HasSortableRelations
        
        HasSortableRelations trait
    
    
 trait Winter\Storm\Database\Traits\HasSortableRelationsUsage:
In the model class definition add:
use \Winter\Storm\Database\Traits\HasSortableRelations;
public $sortableRelations = ['relation_name' => 'sort_order_column'];
To set orders:
$model->setSortableRelationOrder($relationName, $recordIds, $recordOrders);
Methods
public getRelationSortOrderColumn (string $relationName) : string
Get the name of the "sort_order" column.
Parameters
                | Property | Type | Description | 
|---|---|---|
| $relationName | string | string | 
Returns
            string
                public initializeHasSortableRelations () : void
Initialize the HasSortableRelations trait for this model.
Sets the sort_order value if a related model has been attached.
Returns
            void
                
            
            
            
                public
            
                        
            setRelationOrder (string $relationName, string | integer | array $itemIds, array $itemOrders = [])
                            : void
                    
        
        Set the sort order of records to the specified orders. If the orders is undefined, the record identifier is used.
Parameters
                | Property | Type | Description | 
|---|---|---|
| $relationName | string | string | 
| $itemIds | string | integer | array | string | integer | array | 
| $itemOrders | array | array | 
Returns
            void
                protected getSortableRelations () : array
Return all configured sortable relations.
Returns
            array
                protected updateRelationOrder (string $relationName, string | integer | Winter\Sorm\Database\Model $id, string $column, integer $order) : void
Update relation record sort_order.
Parameters
                | Property | Type | Description | 
|---|---|---|
| $relationName | string | string | 
| $id | string | integer | Winter\Sorm\Database\Model | string | integer | Winter\Sorm\Database\Model | 
| $column | string | string | 
| $order | integer | integer | 
Returns
            void
                
            
            ← Previous page
            Winter\Storm\Database\Traits\Encryptable
        
                
            Next page →
            Winter\Storm\Database\Traits\Hashable
        
    
    Copyright © 2025 Winter CMS