> How well does Rails deal with ActiveRecord classes mapping to
> self-referencing tables and other more interesting database complexities?
>
>
>
> i.e. Employees table with supervisor_id and mentor_id both self-referencing
> Employees on the primary key "id"
>
> or Categories table with relation table (Parent_Child_Categories) with
> foreign keys parent_id and child_id both referencing Categories.id allowing
> for infinite nesting of many-many related categories
>
> or Supervisors table extending Employees table with a one-one relationship
> (Supervisors.id = Employees.id) allowing for storage of supervisor-specific
> data
Self-referencing associations can be achieved by specifying some of
the options for AR Associations:
http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html.
However, you might run into problems with selecting data if the table
names are the same:
# where supervisor is an inherited model of Employee
Employee.find :all, :include => :supervisor
I don''t think AR supports extending tables since most database systems
don''t support that feature (I''m fairly certain that MySQL,
SQLite, and
MSSQL don''t). AR supports model inheritance using a single table with
all the fields of all the models. Of course, you may be able to fool
AR by treating your inherited table as a separate model. I personally
haven''t tried it.
--
rick
http://techno-weenie.net