Filtering dataset by a generated column #2326
tomasmiguez
started this conversation in
General
Replies: 1 comment 1 reply
-
In your example, I'm not sure why you couldn't handle the To answer your general question about handling sequel/lib/sequel/model/associations.rb Line 3061 in 96f5e93 complex_expression_sql_append as that code does to implement custom filtering. However, it wouldn't be as simple as calling filter_by_status .
A more direct approach would be overriding def filter_expr(expr, &block)
if expr.is_a?(Hash) && expr.has_key?(:status)
expr = expr.dup
status_cond = expr.delete(:status)
(expr.empty? ? (block ? super(&block) : self) : super).filter_by_status(status_cond)
else
super
end
end It's likely possible to write a plugin that would allow something like: plugin :filter_transformer, status: :filter_by_status |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
we currently have a slight issue that was solved not optimally.
We have a model
Expense
that has associatedPayment
s, both have anamount
. We would like to know when anExpense
is paid, for that we implemented a method:that works fine, the issue we encounter was when trying to filter. We expose an HTTP API that automatically generates payloads based on standard filtering syntax, which gets parsed to
where
s on Sequel's datasets:If we wanted to filter by this
status
property, it wouldn't be possible as there is no mechanism (that I know of) to inject custom logic on dataset'swhere
.What we ended doing is having a plugin that extends the datasets methods with a custom filter, that each model can implement:
The issue with this implementation is that it requires duplicating the parsing of the filters logic inside each model, which is really undesirable for us.
Is there any mechanism or suggestion on how we might extend a dataset's
where
with our custom logic? We would love being able to do something likeand maybe that would call something like
or something like that?
Beta Was this translation helpful? Give feedback.
All reactions