Hey everyone, I'm having a problem related to order of operations when using
the filter() and or() methods on data set.
For a simple example, let's do this: I have a list of IDs, and I want the
addresses that are active and if the primary_office_id or the
secondary_office_id column has one of those IDs like so:
SELECT * FROM addresses WHERE (address.current=true) AND
((primary_office_id IN (1,2,3)) OR (primary_office_id IN (1,2,3)))
A naive attempt would be to use:
ds.filter(:active => true).filter(:primary_office_id =>
ids).or(:secondary_office_id => ids)
BUt this does the order of precedence wrong like so:
SELECT * FROM addresses WHERE (address.current=true) AND (primary_office_id
IN (1,2,3)) OR (primary_office_id IN (1,2,3))
What I need is something like:
ds.filter(:active => true).filter({:primary_office_id => ids,
:secondary_office_id => ids}, :join => :or)
or even
ds.filter(:active => true).filter(:primary_office_id =>
ids).or_with_previous(:secondary_office_id => ids)
This way I can force the OR to be an OR to only the previous filter in the
chain, and not appended on the end. Is there any way to do this? (To
complicate things, the :active => true filter is appended to the dataset well
before the localized method as we are utilizing soft delete.)
Of course, I could use SQL fragment strings, but then I don't get any of the
nice automatic conversion and readability with using the syntax above.
Thanks!
-Jeff R
-----
Jeffrey Reinecke
[email protected]
blog.paploo.net
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.