Hello

Very new to Sequel and Ruby, so bear with

The idea is to return model instances of the table_1 model where the id's 
of table_1 do not exist in table_2 where another_id has a value. This is so 
I can use those instances and the data contained within elsewhere
def self.my_method(another_id:) 
 result = DB["SELECT t1.* FROM table_1 t1 WHERE t1.id NOT IN (SELECT t2.id 
FROM table_2 t2 WHERE t2.another_id = #{another_id})"] 

 result_array = [] 
 result.each do |row| 
     result_array << self.find(id: row[:id]) 
  end 

 result_array 
end 

I have models for both table_1 and table_2

This works but it feels very clunky and probably very inefficient as for 
every id that is returned I am rebuilding an instance of each table_1 model 
by looking at the database again.

How would this be done in a typically Sequel way using the methods made 
available on the Model/Dataset. From my viewpoint I am struggling with how 
I pull together the various pieces of syntax to do this

Thanks in advace

Bromley

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/8bf7537a-fc0d-4769-8370-dca6cdea69dbn%40googlegroups.com.

Reply via email to