Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngRestRelations will not work with ngRestFilters #359

Open
ifuratdev opened this issue Aug 30, 2019 · 2 comments
Open

ngRestRelations will not work with ngRestFilters #359

ifuratdev opened this issue Aug 30, 2019 · 2 comments
Assignees
Labels

Comments

@ifuratdev
Copy link

ifuratdev commented Aug 30, 2019

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 nadar self-assigned this Aug 30, 2019
@nadar nadar added the bug label Aug 30, 2019
@nadar
Copy link
Contributor

nadar commented Aug 30, 2019

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
Copy link
Author

i will check it and let you know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants