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

cydrick.nonog
cydrick.nonog

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

nanohard
nanohard

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.

deroccha
deroccha

same endeffect!!

Last updated

viral-vector
viral-vector

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

deroccha
deroccha

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

viral-vector
viral-vector

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

DjGMory
DjGMory

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.

SergeyKasyanov
SergeyKasyanov

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

viral-vector
viral-vector

also using conditions does not work

xchenxujian9360
Mohsin
axomat
voidshah
kenniko
viorel15030
viorel15030

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

damianlewis
osarzola
osarzola

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;
});
cydrick.nonog
cydrick.nonog

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.