On 5/13/05, Michael Campbell
<michael.campbell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve a table design question; one of my tables is
"products", which
> can refer to itself in a mant-to-many way (to be used in a "people who
> bought "x" might also like these other products..." type web
page).
> 
> A product may have many related products, and any one product may be a
> related product of many others.
> 
> Is there a canonical ActiveRecord way to model this?  And/or some
> schema ideas?  Right now I have a "relatedproducts" table with
id,
> product_id, and related_id (?) in it.  This works conceptually, but
> I''m not sure how it fits in with ActiveRecord just yet.
> 
> Pointers to documentation welcome, if such exists; I DID look before
> posting, but I have probably missed it.
No sweat, just set the AR relationship, and specify the class name with options:
class Product < ActiveRecord::Base
  has_many :related_products, :class_name => ''Product''
I have this working with 2 classes related through single table
inheritance and it works fine.
-- 
rick
http://techno-weenie.net