Problem
Currently, developers can define a hasMany() relations like this:
class Post extends Model {
views() {
return this.hasMany("PostView", "id", "post_id");
}
}
We can fetch the views? with the following query:
GET /api/v1/posts?with=views
But, we are not able to add any condition that relationship queries. Axe API returns all data even though there are one million views. That's not useful.
Suggestion
Developers should be able to define a onBeforeQuery options for hasMany relationship definitions. By using that function, we can limit, or add more conditions as we wish.
Example:
const onBeforeViewQuery = async (req: AxeRequest, query: Knex.QueryBuilder) => {
query.orderBy("id", "desc").limit(2);
}
class Post extends Model {
views() {
return this.hasMany("PostView", "id", "post_id", {
onBeforeQuery: onBeforeViewQuery,
});
}
}
Problem
Currently, developers can define a
hasMany()relations like this:We can fetch the
views?with the following query:GET /api/v1/posts?with=viewsBut, we are not able to add any condition that relationship queries. Axe API returns all data even though there are one million views. That's not useful.
Suggestion
Developers should be able to define a
onBeforeQueryoptions forhasManyrelationship definitions. By using that function, we can limit, or add more conditions as we wish.Example: