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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0bdaf2a5cf0a401d2ee4377b9ce47581?d=identicon&s=25 Tyl Tan (tyanlion)
on 2008-12-07 09:11
(Received via mailing list)
Hi,

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.
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-12-07 09:21
(Received via mailing list)
Helping tyliong in #rubyonrails irc channel
-----
Ryan Bigg
Freelancer
http://frozenplague.net
0bdaf2a5cf0a401d2ee4377b9ce47581?d=identicon&s=25 Tyl Tan (tyanlion)
on 2008-12-07 10:18
(Received via mailing list)
Still unsolved. However != seems to work for integers but not strings.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-07 10:52
(Received via mailing list)
On Dec 7, 9:28 am, "Tan YL" <tyli...@gmail.com> 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.

Fred
0bdaf2a5cf0a401d2ee4377b9ce47581?d=identicon&s=25 Tyl Tan (tyanlion)
on 2008-12-07 10:56
(Received via mailing list)
Thanks fred for your reply I managed to solve it, it was because some of
my
values in the column were nil so it affected the find statement.
This topic is locked and can not be replied to.