# Model#find returns wrong class

**URL:** <https://www.ruby-forum.com/t/model-find-returns-wrong-class/139382>\
**Category:** Rails\
**Created:** [June 3, 2008, 12:42pm UTC](https://www.ruby-forum.com/t/model-find-returns-wrong-class/139382 "2008-06-03T12:42:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [June 3, 2008, 12:42pm UTC](https://www.ruby-forum.com/t/model-find-returns-wrong-class/139382/1 "2008-06-03T12:42:44Z")

</div>

Hi,

I’ve one specific database view which troubles me. I set up a model  
mytestmodel.rb:

class Mytestmodel \< ActiveRecord::Base  
set\_table\_name “shop\_view1”  
end

./script/console output (development environment)

> > Mytestmodel.find(:first)  
> > =\> #\<Product id: 260, …\>

development.log output:  
Mytestmodel Load (0.030650) SELECT \* FROM “shop\_view1” LIMIT 1

Why do I get an object of Product class back here? I guess this is  
somewhere cached. When I change “set\_table\_name” to another view, I get  
a Mytestmodel back, like expected. When I change it back, I always get a  
Product class.

I tried this with rails 2.0.2 and 2.1.0 on ruby 1.8.6 using a postgresql  
8.3 database. All caching options in environments/development.rb are  
turned off.

I restarted everything on my local machine, deleted all files in ./tmp/  
, stopped memcached, but this behaviour still exists.

Any clue where to search for the problem here?

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [June 4, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/model-find-returns-wrong-class/139382/2 "2008-06-04T14:06:12Z")

</div>

Joachim G. wrote:

> > > Mytestmodel.find(:first)  
> > > =\> #\<Product id: 260, …\>

Gotcha!

ActiveRecord uses the table field “type” when determine the model name.  
It doesn’t seem to matter if you have actually a inherited model of that  
type or not. It would be a nice feature if you get a warning here.

Well a simple self.inheritance\_column = “” to the model does the trick
