Table filters : column not found, why ?
Hi everyone ! Is someone here capable to explain how/why table filters have no access to table query column ?
For example : Let's say I have a users table with a calculated "availabilityScore" column (percentage, from 0 to 100). If I want a filter for that "availabilityScore", I can't just use
->where('availabilityScore', '>', 10)
because it will throw a column not found
error.
Why filters are not just modifying the table query ? I'm sure there is good reasons, I just need to understand 🙂 Thanks !3 Replies
is availabilityScore an accessor?
No, I make a
joinSub()
and an addSelect()
in the $table->query()
method. Accessor could work, I thought about it but was concerned about the performance. With an accessor, it will make one additional query to the availabilities
table no ?
And I don't need to load the availabilityScore
each time I get a user, I only need it for this table so I don't want those data to be load each time I load the user model.
For example here, why the $query
is a neutral Builder
(same as doing User::query()
) and not the same query of the table that is used to fill the table, in $table->query()
? Does it mean that, for each filter, it makes another SQL query and then filter the table by IDs comparison ?
Filters will use the table columns to filter results. You might consider creating virtual columns for calculated data