I want to set up a many-to-many recursive association with the model Projects
a Project has_many
Comps (or comparables), which are other Projects
and a Project can be the Comp of many Projects
I'd like to add other columns to each record, so I need a join table
I've done the following research which has not helped:
- This article is a clear basic explanation of sql recursive associations, but there is no specifics on activerecord implementation
- this stack overflow article deals with a one-to-many relationship, and not a many-to-many
- I tried this rails method of setting up what seems to be multiple join tables, but it is confusing and did not work for me.
- I tried this rails method and it did not work for me, maybe because it assigns primary keys to two columns in a table, which I did not do
In the last link, here is the code in question:
CREATE TABLE tutorship (
tutor_id INTEGER,
tutored_id INTEGER,
hasPaid BOOLEAN,
PRIMARY KEY (tutor_id, tutored_id)
);
how can you have two primary keys in the same table? If that is correct, is this the issue, and how do i set this up?
Generally, how do i set this up in active record?