You can give to the `.where` definitions anything that you would give to a
normal #where dataset method. So you can still build complex conditions,
because you have Sequel's expression API at your disposal:
dataset_module do
where :a, Sequel[:a] >= 1
where :b, Sequel[:b] !~ 2
where :c, Sequel[:c].like('3')
end
or via virtual row blocks:
dataset_module do
where(:a) { a >= 1 }
where(:b) { b !~ 2 }
where(:c) { c.like('3') }
end
In that case the conditions are already expression objects, so you can just
`&` and `|` them directly. This means that in
def abnotc
where((Sequel[a_conditions] & b_conditions) | c_conditions)
end
you can lose the Sequel[]:
def abnotc
where((a_conditions & b_conditions) | c_conditions)
end
Jeremy, maybe a note that expressions and virtual row blocks are supported
could be added to the subset_conditions documentation.
Kind regards,
Janko
On Friday, November 2, 2018 at 6:56:41 AM UTC+1, 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.
>
> Thanks again.
>
--
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.