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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Helping tyliong in #rubyonrails irc channel ----- Ryan Bigg Freelancer http://frozenplague.net On 07/12/2008, at 6:10 PM, tyliong wrote:> > 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. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Still unsolved. However != seems to work for integers but not strings. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Ryan Bigg Sent: Sunday, December 07, 2008 4:21 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Find active record condition of not equal Helping tyliong in #rubyonrails irc channel ----- Ryan Bigg Freelancer http://frozenplague.net On 07/12/2008, at 6:10 PM, tyliong wrote:> > 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. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 7, 9:28 am, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Ryan Bigg > Sent: Sunday, December 07, 2008 4:21 PM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Find active record condition of not equal > > Helping tyliong in #rubyonrails irc channel > ----- > Ryan Bigg > Freelancerhttp://frozenplague.net > > On 07/12/2008, at 6:10 PM, tyliong wrote: > > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung Sent: Sunday, December 07, 2008 5:51 PM To: Ruby on Rails: Talk Subject: [Rails] Re: Find active record condition of not equal On Dec 7, 9:28 am, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Ryan Bigg > Sent: Sunday, December 07, 2008 4:21 PM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Find active record condition of not equal > > Helping tyliong in #rubyonrails irc channel > ----- > Ryan Bigg > Freelancerhttp://frozenplague.net > > On 07/12/2008, at 6:10 PM, tyliong wrote: > > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---