Hi, I''ve been stung when deploying a rails app to heroku, and I''m fairly confident the problem is the difference between my local db sqlite3, and the heroku standard free shared db which is postgres(i think). I have a scope in my model that looks like this scope :not_archived, :conditions => [''application_state != "archived"''] The idea is I want to get back all the records where the application_sate value is not equal to the string "archived". This works fine locally, but in the Heroku logs it throws up the following error : ActionView::Template::Error (PG::Error: ERROR: column "archived" does not exist SELECT COUNT(*) FROM "coach_applications" WHERE "coach_applications"."user_id" = 10 AND (application_state !"archived")): It''s looking for a column archived, which is not what I want. Essentially what I want is a proper Rails ORM style scope that returns the rows in a db where the value of column is not equal to something, instead of me having to resort to actual SQL comands in my scope. Any suggestions would be very helpful! I thought this would be easy to find, but the closest I can find is http://stackoverflow.com/questions/5426421/rails-model-find-where-not-equal which still seems pretty messy Thanks -- 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-/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 https://groups.google.com/groups/opt_out.
On Wed, Jul 25, 2012 at 3:32 PM, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, I''ve been stung when deploying a rails app to heroku, and I''m fairly > confident the problem is the difference between my local db sqlite3, and > the heroku standard free shared db which is postgres(i think).Yes, it''s PG.> I have a scope in my model that looks like this > > scope :not_archived, :conditions => [''application_state != "archived"'']> This works fine locally, but in the Heroku logs it throws up the > following error : > > ActionView::Template::Error (PG::Error: ERROR: column "archived" does > not exist > SELECT COUNT(*) FROM "coach_applications" WHERE > "coach_applications"."user_id" = 10 AND (application_state !> "archived")): > > It''s looking for a column archived, which is not what I want.Notice the double quotes around the table name/column in the first part? What happens if you change your scope to the form of [ "application_state != ''archived'' " ] or [ "application_state != ? ", "archived" ] Untested, but PG is annoyingly (IMO) idiosyncratic at times. HTH! -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 https://groups.google.com/groups/opt_out.
On Jul 25, 2012, at 6:38 PM, Hassan Schroeder wrote:> Untested, but PG is annoyingly (IMO) idiosyncratic at times.There is absolutely nothing "idiosyncratic" about a string in double quotes being treated as a column name--it is the SQL standard. If MySQL does not do this, then (as usual when you find a difference between MySQL and PostgreSQL), MySQL is non-compliant. -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- 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 https://groups.google.com/groups/opt_out.
Cheers for the help, yes, the single quotes does solve the problem. Out of interest is there a better way of doing this, I''ve read in numerous places that using raw SQL in rails apps is not a great idea as it means rails cant change the SQL depending on the current database. As no ActiveRecord method has been suggested for ''not equals'' I''m guessing there isn''t an easy one. Do you consider using raw SQl like this bad practice? Or just avoid when possible? Cheers -- 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-/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 https://groups.google.com/groups/opt_out.
Apparently Analagous Threads
- RoR running on Localhost but not on Heroku
- PG gem behaves strange. It requires live DB connection to only generate a model. How to turn it off?
- Application Error!!!!!!!!!!!!!!!!!!!!!!!
- Heroku - Event_Calendar - preventing assets precompile
- missing these required gems: will_paginate