Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>Just a couple of days ago, a similar question was asked: <a href="https://stackoverflow.com/questions/2168442/many-to-many-relationship-with-the-same-model-in-rails">“Many-to-many relationship with the same model in rails?”</a>. I tried to document extensively how to do looped associations there. Perhaps that will help you along?</p></li> <li><p>Tables without IDs in Rails are only ever seen with a <code>has_and_belongs_to_many</code> association. With regular <code>has_many :through</code> associations, the join table's model is like any other ActiveRecord model, and requires an ID column</p></li> <li><p>I'm not aware of a good convention here, but those examples are a bit strange. You'd be accessing them as <code>relationship.your</code>, which feels a bit awkward to me personally. Perhaps <code>your_person_id</code>, which would be accessed as <code>relationship.your_person</code>, and make clear that you're dealing with a <code>Person</code> instance? Another option could be <code>relationship.you</code>.</p></li> <li><p>I've never used acts_as_tree, but you can invoke it with a parameter like so: <code>acts_as_tree :foreign_key =&gt; 'my_id'</code></p></li> </ol> <p>As I mention in my answer to the <a href="https://stackoverflow.com/questions/2168442/many-to-many-relationship-with-the-same-model-in-rails">other question</a>, it looks like your biggest difficulty will be bi-directional relationships. Once a person A is connected to a person B, it is not implied that person B is connected to person A. That's unfortunately difficult to accomplish in ActiveRecord, from what I can tell.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload