so, my model has_many foo. Now, if the bar values change, the foos should be in a different order. Is there anything I can/should/need-to call to force the foos to be immediately reorder (i.e. without going back to the database). David
On 7/25/05, David Corbin <dcorbin-wmGZ+vDKSyrZJqsBc5GL+g@public.gmane.org> wrote:> so, my model has_many foo. Now, if the bar values change, the foos should be > in a different order. Is there anything I can/should/need-to call to force > the foos to be immediately reorder (i.e. without going back to the database).No, the order option is only used when retrieving from the DB. One option you could use is: class Whatever <AR::Base has_many :foos def ordered_foos foos.sort { your comparator } end end> David > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
On Jul 24, 2005, at 6:33 PM, David Corbin wrote:> so, my model has_many foo. Now, if the bar values change, the foos > should be > in a different order. Is there anything I can/should/need-to call > to force > the foos to be immediately reorder (i.e. without going back to the > database).I haven''t ever tried it in this specific circumstance, but the following ought to work: model.foo.sort! { |a,b| a.bar <=> b.bar } - Jamis