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
Post a Comment