My Article model has one boolean field called "draft". I''m using sqlite3 and rails 3.0.3. The boolean column (which was created with :boolean) is storing ''true'' and ''false'' as ''t'' and ''f'' in the database, and the queries appear to be working fine for both cases. The problem is that when I look at the draft attribute on the query result objects, it is always "true": @articles = Article.where(:draft => false) # returns the correct rows logger.debug(@articles[0].draft) # will show ''true'' I know that Ruby treats ''f'' as true, but I''m assuming rails will convert it to false as part of the mapping. Why isn''t it working? Thanks, Jim -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
(Apologies if this ends up being a duplicate. I''ve been battling Google Groups and don''t see the OP on the site so I''m going to try once more.) My Article model has one boolean field called "draft". I''m using sqlite3 and Rails 3.0.3. The boolean column (which was created with :boolean) is storing ''true'' and ''false'' as ''t'' and ''f'' in the database, and the queries appear to be working fine for both cases. The problem is that when I look at the draft attribute on the query result objects, it is always "true": @articles = Article.where(:draft => false) # returns the correct rows logger.debug(@articles[0].draft) # will show ''true'' I know that Ruby treats ''f'' as true, but I''m assuming Rails will convert it to false as part of the mapping. Why isn''t it working? Thanks, Jim -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
There is a value in the column which means true, you need to create a method in the model to translate that for you. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Jan-01 02:12 UTC
Re: Model''s boolean attribute always being set to true?
On Dec 31, 2010, at 3:15 AM, Jim wrote:> My Article model has one boolean field called "draft". I''m using > sqlite3 and rails 3.0.3. The boolean column (which was created > with :boolean) is storing ''true'' and ''false'' as ''t'' and ''f'' in the > database, and the queries appear to be working fine for both cases. > The problem is that when I look at the draft attribute on the query > result objects, it is always "true": > > @articles = Article.where(:draft => false) # returns the correct > rows > logger.debug(@articles[0].draft) # will show ''true''maybe try logger.debug( @articles[0].draft? ) since that''s more explicitly asking "is this true-ish?" Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Kalafut
2011-Jan-01 02:47 UTC
Re: Model''s boolean attribute always being set to true?
I figured it out. I had an error in one of the model callbacks and was overwriting the data that had just been read from the DB. Thanks, Jim -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.