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

voidshah
voidshah

When I investigated soure code of the RelationController, I found this method

 
/**
     * !!!!
     * !!!! WARNING: DO NOT USE - This method is scheduled to be removed
     * !!!!
     *
     * Controller override: Extend the query used for populating the list
     * after the default query is processed.
     * @param October\Rain\Database\Builder $query
     * @param string $field
     */
    public function relationExtendQuery($query, $field)
    {
    }

If this method is removed, how can I replace it??? I need this method or its likeness

planetadeleste
planetadeleste

+1 I don't found how to extend a relation query.

dsqr
dsqr

+1

How else would one achieve the documented functionality?

Extend the query used for populating the list after the default query is processed.
viral-vector
viral-vector

+1 this would solve my issues with scope & conditions not working while setting relationships on custom models

Zarkweb
Zarkweb

+1 again, This is the only way we found to filter results displayed in a relationship manager for now.

Wil there be a replacement solution for that when it'll be deleted ?

Zarkweb
Zarkweb

It seems that you can use events to get your way around :

Event::listen('backend.list.extendQuery', function ($widget, $query) {
    // Test your model
    if ($widget->model instanceof \You\Plugin\Models\YourModel) {
        // Add conditions to the $query
    }
}

I think the docs needs more information on the available events and what we can do with it.

Last updated

voidshah
voidshah

Ok. And tell me, pls, how can I use related field for extend query?! Like here:

 
public function relationExtendQuery($query, $field)
    {
        if ($field == 'same_field') {
           $query->...
        }
    }
jiangzuixian12230
jiangzuixian12230

I use this function too!

Tschallacka
Tschallacka

https://github.com/octobercms/october/issues/1780#issuecomment-186411450

Look at the relationExtendViewWidget and relationExtendManageWidget methods. These are the replacement overrides.

   public function relationExtendViewWidget($widget, $field)
   {
       $widget->bindEvent('list.extendQuery', function() { ... });
   }
Tschallacka
Tschallacka

https://github.com/octobercms/october/issues/1780#issuecomment-186411450

Look at the relationExtendViewWidget and relationExtendManageWidget methods. These are the replacement overrides.

   public function relationExtendViewWidget($widget, $field)
   {
       $widget->bindEvent('list.extendQuery', function() { ... });
   }
faraz10net23375
faraz10net23375

voidshah said:

Ok. And tell me, pls, how can I use related field for extend query?! Like here:

 
public function relationExtendQuery($query, $field)
   {
       if ($field == 'same_field') {
          $query->...
       }
   }

1-11 of 11

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