Forum: Ruby on Rails Find active record condition of not equal

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tyl T. (Guest)
on 2008-12-07 10:11
(Received via mailing list)

I have tried creating a not equal condition in the find statment but
it just outputs an empty array.

model.find(:first, :conditions => [" id = ? AND market = ? AND
promotion <> ? " , id , name, "y"],:order => 'id desc').price

I have tried != instead of <>

I have tried googling for the answer but i can't seem to find it. What
do i need to put to give a not equal condition?

Database is mysql.
Ryan B. (Guest)
on 2008-12-07 10:21
(Received via mailing list)
Helping tyliong in #rubyonrails irc channel
Ryan B.
Tyl T. (Guest)
on 2008-12-07 11:18
(Received via mailing list)
Still unsolved. However != seems to work for integers but not strings.
Frederick C. (Guest)
on 2008-12-07 11:52
(Received via mailing list)
On Dec 7, 9:28 am, "Tan YL" <removed_email_address@domain.invalid> wrote:
> Still unsolved. However != seems to work for integers but not strings.
!= is what you want (except if you testing whether something is not
NULL, if you want your query to also return rows where promotion is
NULL then you will need to change your query). Is promotion a boolean
attribute? If so then you should put ["foo != ?", true] and let
activerecord handle the mapping of true/false to whatever value is
stored in the database.

Tyl T. (Guest)
on 2008-12-07 11:56
(Received via mailing list)
Thanks fred for your reply I managed to solve it, it was because some of
values in the column were nil so it affected the find statement.
This topic is locked and can not be replied to.