# Single table inheritance problem

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-problem/196404>\
**Category:** Rails\
**Created:** [July 22, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/196404 "2007-07-22T14:40:09Z")\
**Posts on this page:** 2\
**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:40pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/196404/1 "2007-07-22T14:40:09Z")

</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

---

<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 23, 2007, 9:59am UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/196404/2 "2007-07-23T09:59:18Z")

</div>

I have to correct myself here.  
Although things work (dont work) in the order described the  
Category expected, got Category  
Error message still appears after a while and then continues to be  
there until a server restart.  
Now this is really a problem! A bit of googling revealed that is has  
to do with the plugins used.  
So these are the plugins used:  
acts\_as\_versioned  
acts\_as\_tree  
globalize

Any idea ?
