Closed markiiman closed 8 years ago
Is this already resolved, @markii1607?
This is considered working
Yes Kuya @ajcastro it was already resolved and it is already working
But the problem for that is when the relation defined in the query param is a reference table, it cannot filter the attributes in the relation.
example:
Post model hasMany Comments Comments model belongsTo Post
URL: GET /comments?relations[post][attributes][]=text
since Post model doesnt have comments_id in it's table, it returns an error.
code in base-repository:
if (is_array($rules) && array_key_exists('attributes', $rules)) {
$eagerLoads[$relation] = function ($q) use ($rules) {
if (!in_array($fk = $this->model->getForeignKey(), $rules['attributes'])) {
array_push($rules['attributes'], $fk);
}
$q->select($rules['attributes']);
};
}
Please change your composer.json. It should be like this. There are major changes in the base-repository which is a dependency. You might need to update your code, because it is backwards incompatible.
Can you please check if there are some bugs around the method eagerLoadRelations in which I refactored? The sql queries are correct, (I used event listener), the output for relations (relations=comment or relations[]=comments) is correct, but for the url
/api/v1/posts?relations[comments][attributes][]=id&relations[comments][attributes][]=text
, it returns null.Attached are some screenshots of the test cases I've encountered. Thanks :)