Wednesday, July 25, 2012

[Rails] rails scope without raw sql

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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate