# Single table inheritance problem

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-problem/110068>\
**Category:** Rails\
**Created:** [July 22, 2007, 2:39pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/110068 "2007-07-22T14:39:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![migo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f14d63/32.png) [@migo](https://www.ruby-forum.com/u/migo)\
**Post date:** [July 22, 2007, 2:39pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/110068/1 "2007-07-22T14:39:07Z")

</div>

Hallo,

I am having a very strange Problem with STI in my application.

setup:

- two tables one called “wikis” on called “categories” with a hbtm  
relationship.
- the wikis table is the sti one with a model PageWiki being extended  
from Wiki (and the correspondig type column)

Following happens:

- server restart
- get :wikis, :show\_pages
- in show\_pages the first line says PageWiki.find(:all)  
! Now I get the following error

LoadError in WikisController#list\_pages  
app/models/page\_wiki.rb to define PageWiki // (it is of course defined  
there )

If i call the page again everythings works as it should be and the the  
error message never appears again until the server restarts  
BUT !  
When I now try to add categories to my wikis with

@wiki = Wiki.find(params[:wiki])  
@category = Category.find(params[:id])  
@wiki.categories \<\< @category unless  
@wiki.categories.index(@category)

I get the VERY unhelpful error messages telling me

ActiveRecord::AssociationTypeMismatch  
in WikisController#add\_category  
Category expected, got Category

This error does not appear if do not call the list\_pages method  
before.

If I change the line PageWiki.find(:all) to  
Wiki.find(:all, :conditions =\>“type=‘PageWiki’”) it all works.

Does anybody have any ideas what happens here?  
Thanks a lot for any help.

migo
