# Order by dynamic field

**URL:** <https://discuss.rubyonrails.org/t/order-by-dynamic-field/10066>\
**Category:** rubyonrails-talk\
**Created:** [March 11, 2007, 2:10pm UTC](https://discuss.rubyonrails.org/t/order-by-dynamic-field/10066 "2007-03-11T14:10:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eden\_li](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@eden\_li](https://discuss.rubyonrails.org/u/eden_li)\
**Post date:** [March 11, 2007, 2:10pm UTC](https://discuss.rubyonrails.org/t/order-by-dynamic-field/10066/1 "2007-03-11T14:10:55Z")

</div>

Yes, why not?

class MyModel \< ActiveRecord::Base &nbsp;&nbsp;def self.some\_calculations(id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find(:all, :conditions =\> ['id != ?', id], :order =\> 'rand()') &nbsp;&nbsp;end end

> > MyModel.some\_calculations(66)

OR drop the self and have an instance method....

class MyModel \< ActiveRecord::Base &nbsp;&nbsp;def some\_calculations &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find(:all, :conditions =\> ['id != ?', id], :order =\> 'rand()') &nbsp;&nbsp;end end

---

<div class="post-metadata">

**Author:** ![fxn](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/fxn/32/12956_2.png) [@fxn](https://discuss.rubyonrails.org/u/fxn)\
**Post date:** [March 11, 2007, 3:56pm UTC](https://discuss.rubyonrails.org/t/order-by-dynamic-field/10066/2 "2007-03-11T15:56:51Z")

</div>

Justas wants to order the rows according to the result of applying some\_calculations() to them.

-- fxn
