On Thursday, November 1, 2018 at 10:56:41 PM UTC-7, cvss wrote:
>
> Thank you for the detailed explanation. It makes sense now. It's the way I
> am thinking that's wrong.
>
> Maybe a raw SQL query is better in this case. But it bothers me that I
> can't think of a way to create reusable methods of sets of records.
>
> My queries aren't that simple as "a=>1" and I want to be able to use
> "Test.a" or "Test.b" and "Test.c".
>
> You can imagine them in a real case as:
>
> Test.cars_with_blue_color
> Test.cars_with_alloy_wheels
> Test.cars_that_need_service
>
> then any of the first two can be used individually but there could be a
> case that a third method can combine those three. For example:
>
> def top_cars_to_sell
> (cars_with_blue_color + cars_with_alloy_wheels) -
> cars_that_need_service
> end
>
> I know that it doesn't work, I am describing my case.
>
> Something like that.
>
You would have to have separate methods that return the expressions used
for filtering:
def blue_color_conditions
{:color=>'blue'}
end
def cars_with_blue_color
where(blue_color_conditions)
end
def top_cars_to_sell
where(Sequel[blue_color_conditions] |
alloy_wheel_conditions).exclude(need_service_conditions)
end
The subset_conditions plugin tries to handle this automatically for you,
but if you have cases where you could not use subset_conditions, you would
need to emulate what is does by separating the expressions used for
filtering from the filtering operation itself.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.