When comparing with nil you have to use IS NULL rather than the usual
comparison operator. where(:read_at => nil) should work though. How
are you using the scope?
When comparing with nil you have to use IS NULL rather than the usual
comparison operator. where(:read_at => nil) should work though. How
are you using the scope?
I am making a call to it through
current_user.received_messages.unread.length which trips a MYSQL Error
|Mysql2::Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ‘==
NULL)’ at line 1: SELECT message_copies.* FROM message_copies WHERE
(message_copies.recipient_id = 1) AND (read_at == NULL)|
When comparing with nil you have to use IS NULL rather than the usual
comparison operator. where(:read_at => nil) should work though. How
are you using the scope?
I am making a call to it through
current_user.received_messages.unread.length which trips a MYSQL Error
|Mysql2::Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ‘==
NULL)’ at line 1: SELECT message_copies.* FROM message_copies WHERE
(message_copies.recipient_id = 1) AND (read_at == NULL)|
is that using where(“read_at == ?”, nil ) ? That’s just invalid
syntax, since the comparison operator operator is = in SQL. NULL is a
special case though - use IS NULL/IS NOT NULL to test for null values.
is that using where(“read_at == ?”, nil ) ? That’s just invalid
syntax, since the comparison operator operator is = in SQL. NULL is a
special case though - use IS NULL/IS NOT NULL to test for null values.
Thanks, that did the trick.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.