Rémi Gagnon
2009-Jan-27 18:46 UTC
Multi table inheritance problem with has_one relationship
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thomas R. Koll
2009-Jan-28 18:52 UTC
Re: Multi table inheritance problem with has_one relationship
Hi, On Jan 27, 7:46 pm, Rémi Gagnon <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rémi Gagnon
2009-Jan-28 19:39 UTC
Re: Multi table inheritance problem with has_one relationship
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 <rails-mailing-l...@andreas-s.net> > 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---