# Multi table inheritance problem with has\_one relationship

**URL:** <https://www.ruby-forum.com/t/multi-table-inheritance-problem-with-has-one-relationship/158762>\
**Category:** Rails\
**Created:** [January 27, 2009, 7:46pm UTC](https://www.ruby-forum.com/t/multi-table-inheritance-problem-with-has-one-relationship/158762 "2009-01-27T19:46:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [January 27, 2009, 7:46pm UTC](https://www.ruby-forum.com/t/multi-table-inheritance-problem-with-has-one-relationship/158762/1 "2009-01-27T19:46:42Z")

</div>

Here is my issue

class TransactionProduct \< ActiveRecord::Base  
has\_one :product, :class\_name =\> ‘Product’  
end

class Product \< ActiveRecord::Base  
set\_inheritance\_column :class\_name  
end

class ProductVT \< Product  
def self.base\_class  
ProductVt  
end  
end

So when I do

Product.find(:first) I got an instance of ProductVT with only the  
columns of Product, which is ok. Then when I do reload like this :

Product.find(:first).reload

I do have a complete instance of ProductVT.

But

When I do nagivate on Product from TransactionProduct and I do reload on  
the instance of ProductVT it does not reload the ProductVT, it does it  
on Product

TransactionProduct.find(:first).product.relaod (reload the product  
instance instead of ProductVT)

Even if I see in the console that is a ProductVT it reloads Product. I  
checked in development.log and in performs the query on Product.

Any idea.

Note : A temp fix is the to do a  
Product.find(TransactionProduct.find(:first).product).reload, which is  
ugly

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [January 28, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/multi-table-inheritance-problem-with-has-one-relationship/158762/2 "2009-01-28T20:10:16Z")

</div>

Hi,

On Jan 27, 7:46 pm, Rémi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> TransactionProduct.find(:first).product.relaod (reload the product  
> instance instead of ProductVT)
> 
> Even if I see in the console that is a ProductVT it reloads Product. I  
> checked in development.log and in performs the query on Product.
> 
> Any idea.

I fear I got lost somewhere but did you know ‘becomes’ ?  
TransactionProduct.find(:first).product(true).becomes(ProductVT)

BTW, the product(true) that I used is is quite(?) the same like  
product.reload

ciao, tom

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [January 28, 2009, 8:39pm UTC](https://www.ruby-forum.com/t/multi-table-inheritance-problem-with-has-one-relationship/158762/3 "2009-01-28T20:39:54Z")

</div>

Thanks Tom for the suggestion. I did not know this. But the bads new  
is that does the same issue.

It looks like the superclass name is cached in the association then even  
if I do a reload or (true) and becomes, it fetch the data from Product  
instead of ProductVT

RÃ©mi

Thomas r. Koll wrote:

> Hi,
> 
> On Jan 27, 7:46ï¿½pm, Rï¿½mi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > TransactionProduct.find(:first).product.relaod ï¿½(reload the product  
> > instance instead of ProductVT)
> > 
> > Even if I see in the console that is a ProductVT it reloads Product. ï¿½I  
> > checked in development.log and in performs the query on Product.
> > 
> > Any idea.
> 
> I fear I got lost somewhere but did you know ‘becomes’ ?  
> TransactionProduct.find(:first).product(true).becomes(ProductVT)
> 
> BTW, the product(true) that I used is is quite(?) the same like  
> product.reload
> 
> ciao, tom
