On Tue, 29 Mar 2005 15:43:04 +0000, Pranav Bihari
<pbihari-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:> Hi,
>
> I have the following two models:
>
> class Product < ActiveRecord::Base; end
> class Book < Product; end
>
> Product has "name", "type" fields.
> Book has "isbn", "product_id" fields.
>
> In my view for /books/list.rhtml, I am unable to use <%= book.isbn %>
to
> access the "isbn" attribute of book.
> I am able to use <%= book.name %> though (which the book inherited
from
> product).
> In my view for /products/list.rhtml, I am unable to use <%= product.isbn
%>
> So am I reduced to being able to access only the parent class''
attributes?
>
> How does one access the object attributes with single-table inheritance?
I believe that Single Table Inheritance uses the same table. So in
your example, Book is using products, which has no isbn field.
I think you want to use associations. Product has_many books and a
Book belongs_to a Product.
http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html
--
rick
http://techno-weenie.net