# Refactoring Help

**URL:** <https://www.ruby-forum.com/t/refactoring-help/117982>\
**Category:** Rails\
**Created:** [October 22, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/refactoring-help/117982 "2007-10-22T23:18:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![randomutteringsSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@randomutteringsSS](https://www.ruby-forum.com/u/randomutteringsSS)\
**Post date:** [October 22, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/refactoring-help/117982/1 "2007-10-22T23:18:13Z")

</div>

I’m using find\_by\_sql in my barcode model and I want to use the  
will\_paginate plugin with it. will\_paginate works like a find  
replacement so I need to modify this code to use a regular find method  
instead of find\_by\_sql.

def self.all(client\_id)  
self.find\_by\_sql(“select \* from barcodes inner join items on  
barcodes.item\_id = items.id inner join item\_types on  
items.item\_type\_id = item\_types.id where barcodes.client\_id = " +  
client\_id.to\_s + " order by item\_types.name, items.name”)  
end

Barcode belongs to Item  
Item belongs to ItemType

The reason for this find\_by\_sql is that I want the barcodes sorted  
first by item\_type.name then by item.name.

---

<div class="post-metadata">

**Author:** ![randomutteringsSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@randomutteringsSS](https://www.ruby-forum.com/u/randomutteringsSS)\
**Post date:** [October 23, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/refactoring-help/117982/2 "2007-10-23T15:31:20Z")

</div>

Nevermind, I figured it out.

self.find\_all\_by\_client\_id(client\_id, :include =\> {:item  
=\> :item\_type}, :order =\> “item\_types.name, items.name”)

On Oct 22, 5:17 pm, “randomutterings…” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
