I’m pretty much a newbie to Rails and I have at least two projects
under development that are going to need the same type of constructs
and I’m struggling to get my head around how to achieve what I want
using Rails models and relationships.
In one project I have a hierarchy of (geographical) sites. For
If I were using any other language my sites model would look like:
id, # Primary Key
parent_id # references the id of this site’s parent.
In Rails I think I need to:
- Drop the parent_id column
- Use a bridge table to bridge the site id back to the parent site
- A has_and_belongs_to_many relationship
Is this the correct approach?
I’m sure this must have been done before as I have two projects that I
want to do the same thing in. I’ve found examples in the wiki of
bridging two tables in this way; but I’ve not found a way of linking a
table back to itself.
Any assistance will be gratefully appreciated.