Hello,
i have a column in my table ''is_inappropriate'' which is
boolean,
but can be null
Here is my simplified code, and i want to keep conditions in hash
type.
@reviews || Review.find(
:all,
:conditions => {:is_inappropriate => false})
sql result is :
select * from reviews where reviews.is_inappropriate = False
but this is what i want :
select * from reviews where reviews.is_inappropriate IS NOT TRUE
someone can helps me?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Jean-sébastien Jney wrote:> Hello, > i have a column in my table ''is_inappropriate'' which is boolean, > but can be null > Here is my simplified code, and i want to keep conditions in hash > type. > @reviews ||> Review.find( > :all, > :conditions => {:is_inappropriate => false}) > > sql result is : > select * from reviews where reviews.is_inappropriate = False > > but this is what i want : > select * from reviews where reviews.is_inappropriate IS NOT TRUE > > someone can helps me?eh, maybe this? @reviews || Review.find( :all, :conditions => {:is_inappropriate => ''IS NOT TRUE''}) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just use: :conditions => "is_inappropriate IS NOT TRUE" Chris On Apr 17, 7:20 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > i have a column in my table ''is_inappropriate'' which is boolean, > but can be null > Here is my simplified code, and i want to keep conditions in hash > type. > @reviews ||> Review.find( > :all, > :conditions => {:is_inappropriate => false}) > > sql result is : > select * from reviews where reviews.is_inappropriate = False > > but this is what i want : > select * from reviews where reviews.is_inappropriate IS NOT TRUE > > someone can helps me?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
:conditions => {:is_inappropriate => ''IS NOT TRUE''})
doesn''t work and
i''m aware that :conditions can be a string but i want to have an hash
On Apr 17, 11:20 pm, Chris Mear
<c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org>
wrote:> Just use:
>
> :conditions => "is_inappropriate IS NOT TRUE"
>
> Chris
>
> On Apr 17, 7:20 pm, Jean-Sébastien
<jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
> > Hello,
> > i have a column in my table ''is_inappropriate''
which is boolean,
> > but can be null
> > Here is my simplified code, and i want to keep conditions in hash
> > type.
> > @reviews ||> > Review.find(
> > :all,
> > :conditions => {:is_inappropriate => false})
>
> > sql result is :
> > select * from reviews where reviews.is_inappropriate = False
>
> > but this is what i want :
> > select * from reviews where reviews.is_inappropriate IS NOT TRUE
>
> > someone can helps me?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Well, I''m afraid you can''t have a hash. The hash style lets you test equality, or a range. Those are the only options. If you want to generate the SQL "IS NOT TRUE", then you have to use another style. Chris On Apr 17, 10:50 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> :conditions => {:is_inappropriate => ''IS NOT TRUE''}) doesn''t work and > i''m aware that :conditions can be a string but i want to have an hash > > On Apr 17, 11:20 pm, Chris Mear <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote: > > > Just use: > > > :conditions => "is_inappropriate IS NOT TRUE" > > > Chris > > > On Apr 17, 7:20 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > Hello, > > > i have a column in my table ''is_inappropriate'' which is boolean, > > > but can be null > > > Here is my simplified code, and i want to keep conditions in hash > > > type. > > > @reviews ||> > > Review.find( > > > :all, > > > :conditions => {:is_inappropriate => false}) > > > > sql result is : > > > select * from reviews where reviews.is_inappropriate = False > > > > but this is what i want : > > > select * from reviews where reviews.is_inappropriate IS NOT TRUE > > > > someone can helps me?--~--~---------~--~----~------------~-------~--~----~ 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 chris, do you know if it is possible to mix hash and string value in :conditions ? On Apr 18, 12:07 am, Chris Mear <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:> Well, I''m afraid you can''t have a hash. The hash style lets you test > equality, or a range. Those are the only options. If you want to > generate the SQL "IS NOT TRUE", then you have to use another style. > > Chris > > On Apr 17, 10:50 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > :conditions => {:is_inappropriate => ''IS NOT TRUE''}) doesn''t work and > > i''m aware that :conditions can be a string but i want to have an hash > > > On Apr 17, 11:20 pm, Chris Mear <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote: > > > > Just use: > > > > :conditions => "is_inappropriate IS NOT TRUE" > > > > Chris > > > > On Apr 17, 7:20 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > Hello, > > > > i have a column in my table ''is_inappropriate'' which is boolean, > > > > but can be null > > > > Here is my simplified code, and i want to keep conditions in hash > > > > type. > > > > @reviews ||> > > > Review.find( > > > > :all, > > > > :conditions => {:is_inappropriate => false}) > > > > > sql result is : > > > > select * from reviews where reviews.is_inappropriate = False > > > > > but this is what i want : > > > > select * from reviews where reviews.is_inappropriate IS NOT TRUE > > > > > someone can helps me?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, you can do something like this:
query = "Jean"
self.find(:all, :conditions =>
["name = :name AND is_inappropriate IS NOT TRUE",
{:name => query}])
In other words, if you pass an array consisting of a string and a
hash, the find method will substitute values in the string (like
":name" in this example) using the values that you''ve passed
in the
hash.
Chris
On Apr 17, 11:35 pm, Jean-Sébastien
<jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> thanks chris, do you know if it is possible to mix hash and string
> value in :conditions ?
>
> On Apr 18, 12:07 am, Chris Mear
<c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:
>
> > Well, I''m afraid you can''t have a hash. The hash
style lets you test
> > equality, or a range. Those are the only options. If you want to
> > generate the SQL "IS NOT TRUE", then you have to use another
style.
>
> > Chris
>
> > On Apr 17, 10:50 pm, Jean-Sébastien
<jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > wrote:
>
> > > :conditions => {:is_inappropriate => ''IS NOT
TRUE''}) doesn''t work and
> > > i''m aware that :conditions can be a string but i want to
have an hash
>
> > > On Apr 17, 11:20 pm, Chris Mear
<c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > Just use:
>
> > > > :conditions => "is_inappropriate IS NOT TRUE"
>
> > > > Chris
>
> > > > On Apr 17, 7:20 pm, Jean-Sébastien
<jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > > wrote:
>
> > > > > Hello,
> > > > > i have a column in my table
''is_inappropriate'' which is boolean,
> > > > > but can be null
> > > > > Here is my simplified code, and i want to keep
conditions in hash
> > > > > type.
> > > > > @reviews ||> > > > >
Review.find(
> > > > > :all,
> > > > > :conditions => {:is_inappropriate =>
false})
>
> > > > > sql result is :
> > > > > select * from reviews where reviews.is_inappropriate =
False
>
> > > > > but this is what i want :
> > > > > select * from reviews where reviews.is_inappropriate IS
NOT TRUE
>
> > > > > someone can helps me?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Just in case you weren''t aware... the second you do ''is_inappropriate IS NOT TRUE'' you lock yourself into a specific database. Some databases treat TRUE as true, some use T., some use 1. Yuk. Of course, that''s not usually a problem but I thought I''d point it out. On 4/20/07, Chris Mear <chris-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:> > > Yeah, you can do something like this: > > query = "Jean" > > self.find(:all, :conditions => > ["name = :name AND is_inappropriate IS NOT TRUE", > {:name => query}]) > > In other words, if you pass an array consisting of a string and a > hash, the find method will substitute values in the string (like > ":name" in this example) using the values that you''ve passed in the > hash. > > Chris > > On Apr 17, 11:35 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > thanks chris, do you know if it is possible to mix hash and string > > value in :conditions ? > > > > On Apr 18, 12:07 am, Chris Mear <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote: > > > > > Well, I''m afraid you can''t have a hash. The hash style lets you test > > > equality, or a range. Those are the only options. If you want to > > > generate the SQL "IS NOT TRUE", then you have to use another style. > > > > > Chris > > > > > On Apr 17, 10:50 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > > :conditions => {:is_inappropriate => ''IS NOT TRUE''}) doesn''t work > and > > > > i''m aware that :conditions can be a string but i want to have an > hash > > > > > > On Apr 17, 11:20 pm, Chris Mear <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Just use: > > > > > > > :conditions => "is_inappropriate IS NOT TRUE" > > > > > > > Chris > > > > > > > On Apr 17, 7:20 pm, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > wrote: > > > > > > > > Hello, > > > > > > i have a column in my table ''is_inappropriate'' which is > boolean, > > > > > > but can be null > > > > > > Here is my simplified code, and i want to keep conditions in > hash > > > > > > type. > > > > > > @reviews ||> > > > > > Review.find( > > > > > > :all, > > > > > > :conditions => {:is_inappropriate => false}) > > > > > > > > sql result is : > > > > > > select * from reviews where reviews.is_inappropriate = False > > > > > > > > but this is what i want : > > > > > > select * from reviews where reviews.is_inappropriate IS NOT TRUE > > > > > > > > someone can helps me? > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---