# Using "vanilla model" for find\_by\_sl()

**URL:** <https://www.ruby-forum.com/t/using-vanilla-model-for-find-by-sl/188213>\
**Category:** Rails\
**Created:** [May 7, 2010, 7:22pm UTC](https://www.ruby-forum.com/t/using-vanilla-model-for-find-by-sl/188213 "2010-05-07T19:22:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [May 7, 2010, 7:22pm UTC](https://www.ruby-forum.com/t/using-vanilla-model-for-find-by-sl/188213/1 "2010-05-07T19:22:10Z")

</div>

I have several hairy SQL queries that join and select columns from  
multiple tables. The standard AR pattern:

MyModel.find\_by\_sql(hairy\_sql\_query)

has rules about which attributes in MyModel are preserved and which  
attributes are added as a result of the query. The problem is that the  
dynamic finders and accessor methods from MyModel can intermingle and  
sometimes shadow attributes returned as a result of the query.

It seems you could create a vanilla model:

class Vanilla \< ActiveRecord::Base  
end

whose sole job is to act as a container for find\_by\_sql() queries, e.g.:

Vanilla.find\_by\_sql(hairy\_sql\_query)

Can you think of any flaws to this approach (before I go and create a  
new git branch :)?

- ff
