Perfect! Thank you Adam.

On Wednesday, 18 October 2017 00:53:25 UTC+11, Adam Daniels wrote:
>
> On Tuesday, October 17, 2017 at 7:16:13 AM UTC-4, Beth Skurrie wrote:
>>
>> Imagine I have a table that has two pairs of coordinates, start_x, 
>> start_y and end_x, end_y. I'm trying to find all lines that connect two 
>> points 1,1 and 2,2, without knowing which is the start and which is the end.
>>
>> This is almost there, but not quite.
>>
>> irb(main):004:0> DB[:lines].where(start_x: 1, start_y: 1).or(start_x: 2, 
>> start_y: 2).where(end_x: 1, end_y: 1).or(end_x: 2, end_y: 2)
>> => #<Sequel::SQLite::Dataset: "SELECT * FROM `lines` WHERE (((((`start_x` 
>> = 1) AND (`start_y` = 1)) OR ((`start_x` = 2) AND (`start_y` = 2))) AND 
>> (`end_x` = 1) AND (`end_y` = 1)) OR ((`end_x` = 2) AND (`end_y` = 2)))">
>>
>> The red part is where it goes wrong. I want it to do:
>>
>> SELECT * FROM `lines` WHERE (((`start_x` = 1) AND (`start_y` = 1)) OR 
>> ((`start_x` 
>> = 2) AND (`start_y` = 2))) AND (((`end_x` = 1) AND (`end_y` = 1)) OR 
>> ((`end_x` 
>> = 2) AND (`end_y` = 2)))
>>
>> I've trawled through all the querying documentation I can find, but 
>> haven't been able to find an answer. Any help would be appreciated. 
>>
>> Thanks.
>>
>
> How about this?
>
>     DB[:lines].where { Sequel.|({start_x: 1, start_y: 1}, {start_x: 2, 
> start_y: 2}) & Sequel.|({ end_x: 1, end_y: 1 }, { end_x: 2, end_y: 2 }) } 
>     # => "SELECT * FROM lines WHERE ((((start_x = 1) AND (start_y = 1)) OR 
> ((start_x = 2) AND (start_y = 2))) AND (((end_x = 1) AND (end_y = 1)) OR 
> ((end_x = 2) AND (end_y = 2))))"
>
>
>

-- 
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.

Reply via email to