luyadev / luya-module-admin

Administration base module for all LUYA admin modules
https://luya.io
MIT License
48 stars 56 forks source link

ngRestRelations will not work with ngRestFilters #359

Open ifuratdev opened 5 years ago

ifuratdev commented 5 years ago

When adding ngRestFilters on a list as a result of ngRestRelations, the filter will show all rows regardless of the relationship

for example 1- in the news module, from the categories list if you select "Articles" list through the relationship for "Category 01"
2- Then from the list of news for "Category 01" if you filter on is_online using ngRestFilters, it will show all news for all categories

ngRestRelations code public function ngRestRelations() { return [ ['label' => 'Articles', 'targetModel' => Article::class, 'dataProvider' => $this->getArticles()], ]; }

public function getArticles() { return $this->hasMany(Article::class, ['cat_id' => 'id']); }

ngRestFilters code

public function ngRestFilters() { return [ 'Online' => self::ngRestFind()->andWhere(['=', 'is_online', 1]), 'Offline' => self::ngRestFind()->andWhere(['=', 'is_online', 0]), ]; }

Image 1: News list

relationship_ngRestFilters_01

Image 2: Categories list

relationship_ngRestFilters_04

Image 3: News for Category 2 using ngRestRelations

relationship_ngRestFilters_02

Image 4: (The issue) News for Category 2 using ngRestRelations after using ngRestFilters

relationship_ngRestFilters_03
nadar commented 5 years ago

Yes, i have to admit, this is true. In ngrest relation context, the filter won't have those context informations, as those "raw" data providers will be returned:

public function ngRestFilters() {
return [
 'Online' => self::ngRestFind()->andWhere(['=', 'is_online', 1]), 
'Offline' => self::ngRestFind()->andWhere(['=', 'is_online', 0]), 
];
 }

We would need something like:

'Online' => $this->findContext()->andWhere(...)

Thanks for the report.

ifuratdev commented 5 years ago

i will check it and let you know