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

Hi,

i have a proble regarding scope

I have a A Model that related to B Model.

this is the code of my model A

public $hasMany = [
        'emails' => ['Author\Plugin\Models\BModel', 'scope' => 'isEmail']
    ];

My B model have this function

public function scopeIsEmail($query){
        return $query->where('field_type','=','email');
    }

The problem is it still get all record even. I just want that all email field must be showned.

Last updated

Bump. Same problem, all records still get shown, along with the fact that even if the record has been selected the only thing scope does is show the record in the list again.

same endeffect!!

Last updated

bump. Having the same issue. 'Scope' nor 'conditions' filter the relationship list.

What kind of backend widget are you using to project the relationship? In my case was recordfinder. I started to use the classic dropdown that was working

I am using the default relation manager -> http://codeshare.io/2dRBu

Encountering the same thing, though only with columns.yaml.

When I try calling the scoped relationship in a twig template, for instance, the scope is recognized.

But when trying to call that scoped relationship in a list via the columns.yaml file, the scope is ignored and the full model is retrieved.

same problem here. scoped relation works fine for type: relation, but not for recordfinder

also using conditions does not work

same problem

+1

+1

+1

+1

Any updates on this issue ? Tried it now and still not working.

+1

I think that feature is incomplete but a little workaround

public $hasMany = [
        'emails' => ['Author\Plugin\Models\BModel']
    ];
public function scopeIsEmail($query){
        return $query->where('field_type','=','email');
    }

Do a custom method in your model B and chain the scope

//custom name because will be have troubles with the __call magic method
public function email()
{
return $this->emails()->isEmail()->get();
}
$model = new Model();
$model->email()->each(function($item){
    //your related record
   $item;
});

Dear all,

I already created a plugin that will solved this problem

You can use this plugin for the solution for this

https://octobercms.com/plugin/cyd293-extenders

Thanks

1-18 of 18

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