ruby on rails - How to return boolean result in named_scope? -


named_scope :incomplete?, lambda { |user_id, todo_id|    { :select => 1, :conditions =>     [ "#{user_id} not in (select user_todos.user_id user_todos) ,        #{todo_id} not in (select user_todos.todo_id user_todos)" ]   }  } 

i'm getting nil result. want return true. gotta do!?

also, there better way write this?

there's huge issue code: named scopes not intended return booleans or single values, intended returns filters chained.

use class method instead. also, use interpolation, don't write values directly sql code.

class yourmodel   def self.incomplete?(user_id, todo_id)     exists?(["? not in (select user_todos.user_id user_todos) , ? not in (select user_todos.todo_id user_todos)", user_id, todo_id])   end end 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -