lambda with inner join

Ruby code posted by Tony Perrie
created at 25 Oct 00:05

Edit | Back
1
2
3
4
  lambda { |objs| { :select => "domain_objects.*, count(links.from_id) AS object_count", 
                    :conditions => objs.inject("TRUE") { |str,obj| str + " OR ( links.object_value.id = '#{obj.id}' AND links.object_value_type = '#{obj.class}' )" },
                    :joins => "INNER JOIN links ON links.from_id = domain_objects.id", 
                    :group => "links.from_id,links.object_value_type HAVING object_count >= #{objs.to_a.size}" } }
464 Bytes in 4 ms with coderay