mctorre
mctorre

Hi, I have 2 tables: event (id, event_name, created_at, updated_at ) and event_attributes(event_id, attribute_type, attribute_value) and their models with their respective relationships. I have a list that displays the Event name, event creation date and the status (which is in event_attributes('event_id','status', 'draft')). This is my columns.yaml file:


columns:
    event_name:
        label       : Event
        searchable  : true

    status:
        label       : Status
        searchable  : true
        relation    : status
        select      : attribute_value

    created_at:
        label       : Created on

Event Model:


public $hasOne = [                                                                                                                  
    'status'        => ['Plugin\Events\Models\EventAttributes', 'key'=> 'event_id', 'otherKey'=> 'id', 'scope' => 'status'],       
];                                                                                                                                  

EventAttributes Model:


 public $belongsTo       = ['event' => 'Plugin\Events\Models\Event', 'key'=> 'id'];

 public function scopeStatus($query)
    {
        $query->where('attribute_type', '"status"')->groupBy('attribute_value')->orderBy('attribute_value', 'desc');

    }

List is working, all columns are searchable and sortable. I want to add a filter to be able to filter by status but I don't know how to do it. I've tried several things but can't find the right way. How can I filter by this value which is in the relationship?

I've tried this but it's not working:


scopes:
    event_name:
        label       : Event
        type        : group
        modelClass  : Plugin\Events\Models\Event
        nameFrom    : event_name
        conditions  : id in (:filtered)

    status:
        label       : Status
        type        : group
        modelClass  : Plugin\Events\Models\EventAttributes
        nameFrom    : attribute_value

Thanks!

Last updated

fausto
info21845
zakir2229
bayram4ik
bayram4ik

I think there is missing conditions in status scope.

netsmertia
netsmertia

Any help in this matter.

mjauvin
mjauvin

Just read the documentation, it's all there: https://octobercms.com/docs/backend/lists#list-filters

Last updated

1-7 of 7