I do this in my model. named_scope :popular, :order => ''name'', :conditions => [''popular_resort = ?'', true] default_scope :order => ''resort_height DESC, name'' By default my resorts are sorted by resort_height then name - works fine. Then when I do this Resort.popular I wish to override the sort order I want my popular resorts sorted by name NOT altitude It does not work? Resort.popular does this.. SELECT * FROM "resorts" WHERE (popular_resort = ''t'') ORDER BY resort_height DESC, name i.e. it''s still doing the ORDER BY resort_height DESC bit which I don''t want. What am I missing here? -- Posted via ruby-forum.com.
Bingo Bob, Just tried this out on my own machine. Works fine for me. What version of ActiveRecord are you using? On Sep 19, 7:31 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I do this in my model. > > named_scope :popular, :order => ''name'', :conditions => > [''popular_resort = ?'', true] > default_scope :order => ''resort_height DESC, name'' > > By default my resorts are sorted by resort_height then name - works > fine. > > Then when I do this Resort.popular I wish to override the sort order > > I want my popular resorts sorted by name NOT altitude > > It does not work? Resort.popular does this.. > > SELECT * FROM "resorts" WHERE (popular_resort = ''t'') ORDER BY > resort_height DESC, name > > i.e. it''s still doing the ORDER BY resort_height DESC bit which I don''t > want. > > What am I missing here? > -- > Posted viahttp://www.ruby-forum.com.
Bingo Bob! Here''s the code I used to test this: pastie.org/622639 Copy/paste that into a new .rb file and run it. If the results come out as you''d expect ("resort_1" then "resort_5") then the issue is in your code somplace. If they don''t, then it may be your version of ActiveRecord. Hope that helps? Gavin handyrailstips.com On Sep 19, 7:31 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I do this in my model. > > named_scope :popular, :order => ''name'', :conditions => > [''popular_resort = ?'', true] > default_scope :order => ''resort_height DESC, name'' > > By default my resorts are sorted by resort_height then name - works > fine. > > Then when I do this Resort.popular I wish to override the sort order > > I want my popular resorts sorted by name NOT altitude > > It does not work? Resort.popular does this.. > > SELECT * FROM "resorts" WHERE (popular_resort = ''t'') ORDER BY > resort_height DESC, name > > i.e. it''s still doing the ORDER BY resort_height DESC bit which I don''t > want. > > What am I missing here? > -- > Posted viahttp://www.ruby-forum.com.
I get this running your program rupes-macbook:Sites rupe$ ruby scope_test.rb resort_5 resort_5 rupes-macbook:Sites rupe$ hmmm, that doesn''t seem right? Then, what''s going on here. -- Posted via ruby-forum.com.
in case it helps $ ./script/about About your application''s environment Ruby version 1.8.7 (universal-darwin10.0) RubyGems version 1.3.5 Rack version 1.0 bundled Rails version 2.3.2 Active Record version 2.3.2 Action Pack version 2.3.2 Active Resource version 2.3.2 Action Mailer version 2.3.2 Active Support version 2.3.2 Edge Rails revision f0d962381a69213d3089a30ca1300826da9ec7e7 Application root /Users/rupe/Sites/foo Environment development Database adapter sqlite3 Database schema version 20090912105013 -- Posted via ruby-forum.com.
Bob, I''m running Rails 2.3.4 now - so ActiveRecord 2.3.4 This definitely works fine on my machine so I''d guess it was a bug in ActiveRecord 2.3.2. would you consider updating your application to rails 2.3.4? Gavin On Sep 19, 2:40 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> in case it helps > > $ ./script/about > > About your application''s environment > Ruby version 1.8.7 (universal-darwin10.0) > RubyGems version 1.3.5 > Rack version 1.0 bundled > Rails version 2.3.2 > Active Record version 2.3.2 > Action Pack version 2.3.2 > Active Resource version 2.3.2 > Action Mailer version 2.3.2 > Active Support version 2.3.2 > Edge Rails revision f0d962381a69213d3089a30ca1300826da9ec7e7 > Application root /Users/rupe/Sites/foo > Environment development > Database adapter sqlite3 > Database schema version 20090912105013 > -- > Posted viahttp://www.ruby-forum.com.
Gavin Morrice wrote:> Bob, > I''m running Rails 2.3.4 now - so ActiveRecord 2.3.4 > > This definitely works fine on my machine so I''d guess it was a bug in > ActiveRecord 2.3.2. > > would you consider updating your application to rails 2.3.4? > > Gavin > > On Sep 19, 2:40�pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Yeah sure - I don''t want to break anything though, and i''ve "frozen" rails into vendor. Is it easy to upgrade and get it into my git repo and deploy, I guess it is!? What steps? -- Posted via ruby-forum.com.
Change the rails version constant in environment.rb to 2.3.4 then run: rake rails:freeze:gems # freezes the newer version in vendor rake rails:update # updates any necessary config and script files I''m pretty sure that''s all you need to do. It shouldn''t break anything although you might notice some behaviors changing (like the default_scope working as expected) so re-run all of your tests to be sure. If you want to try it on a separate git branch to be safe: git add . # add all the current files git commit -a -m "Updating to Rails 2.3.4" # commit current settings to git git branch update # create a new branch git checkout update # move to new branch # then do the necessary steps to update # make sure everything is working as expected git checkout master # move back to master branch git merge update # merge the changes if you''re happy with them git merge update That oughtta do it. Let me know if that solves the issue? Gavin On Sep 19, 3:07 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gavin Morrice wrote: > > Bob, > > I''m running Rails 2.3.4 now - so ActiveRecord 2.3.4 > > > This definitely works fine on my machine so I''d guess it was a bug in > > ActiveRecord 2.3.2. > > > would you consider updating your application to rails 2.3.4? > > > Gavin > > > On Sep 19, 2:40 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Yeah sure - I don''t want to break anything though, and i''ve "frozen" > rails into vendor. > > Is it easy to upgrade and get it into my git repo and deploy, I guess it > is!? > > What steps? > -- > Posted viahttp://www.ruby-forum.com.On Sep 19, 3:07 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gavin Morrice wrote: > > Bob, > > I''m running Rails 2.3.4 now - so ActiveRecord 2.3.4 > > > This definitely works fine on my machine so I''d guess it was a bug in > > ActiveRecord 2.3.2. > > > would you consider updating your application to rails 2.3.4? > > > Gavin > > > On Sep 19, 2:40 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Yeah sure - I don''t want to break anything though, and i''ve "frozen" > rails into vendor. > > Is it easy to upgrade and get it into my git repo and deploy, I guess it > is!? > > What steps? > -- > Posted viahttp://www.ruby-forum.com.
You nailed it. The scoping and sorting is working as expected. Can''t believe it was a bug in rails! Thanks a mil. My app is now running on 2.3.4 to boot, which I guess is better by .2 ! :-). bb -- Posted via ruby-forum.com.
you''re welcome :) On Sep 19, 4:04 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> You nailed it. The scoping and sorting is working as expected. > Can''t believe it was a bug in rails! > Thanks a mil. > My app is now running on 2.3.4 to boot, which I guess is better by .2 ! > :-). > > bb > -- > Posted viahttp://www.ruby-forum.com.