0

I have a rails 2.3.8 application which I migrated to rails 3.0.10 However after migration, I could see issues using default_scope in the models. I am baffled why it is coming , though everything worked fine previously .I am using pg 0.11 gem . In the development logs I could see , while loading the model table ,it is trying to do order by name instead of order by rel_name in the pg_class table . Earlier before the upgrade , the same piece of code works fine.

TestGroup::PgClass Load (1.1ms) SELECT "pg_class".* FROM "pg_class" WHERE "pg_class"."relname" = 'test_groups' ORDER BY UPPER(name) ASC, relname LIMIT 1 PGError: ERROR: column "name" does not exist

class TestGroup < ActiveRecord::Base
  default_scope :order => "UPPER(name) ASC"
 <other piece of code...>
end

This is driving me nuts . I tried changing the default_scope code in the model but that doesn't helped out . order("UPPER(#table_name}.name) ASC")

Any help is much appreciated .Is there any issue how rails and pg gem interact with each other ?

Gaurav
  • 111
  • 8
  • This might be because you have added the `name` column in later migration. And you are migrating all from scratch. You can try commenting default migration and then run migrations. – jbmyid May 14 '14 at 11:27
  • @jbmyid I haven't run the migrations . Using the existing staging db. – Gaurav May 14 '14 at 11:34
  • Can you try `default_scope :order => "UPPER('name') ASC"` – Thaha kp May 14 '14 at 11:36
  • @Thahakp That doesn't worked out,same issue persists even after your change .Below the development logs "SELECT "pg_class".* FROM "pg_class" WHERE "pg_class"."relname" = 'test_groups' ORDER BY UPPER('name') ASC, relname LIMIT 1" – Gaurav May 14 '14 at 11:42
  • `default_scope order("UPPER(name) ASC")` also not working? – Thaha kp May 14 '14 at 11:49
  • @Thahakp That too doesn't worked as well. I have tried that already – Gaurav May 14 '14 at 11:50
  • Try by updating pg gem `gem update pg` and use new syntax `default_scope order("UPPER(name) ASC")` – Thaha kp May 14 '14 at 12:00
  • @Thahakp Updating pg gem has lot of dependency .It requires the gem version to be updated to > 1.8.25. Currently my gem version is 1.3.7 . I had a bad experience while updating the gem version. Can you suggest something that doesn't requires an update – Gaurav May 14 '14 at 12:32
  • is `TestGroup.select(:name).all` is working? check this from the rails console.. – Thaha kp May 14 '14 at 13:38
  • I think you are not understanding the gist of question . The problem is how the rails is loading the model using the pg tables. Everything else is working fine . – Gaurav May 14 '14 at 14:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52703/discussion-between-gaurav-and-thaha-kp) – Gaurav May 14 '14 at 19:34

0 Answers0