I want to retrieve all places
where parent_place_id = 999
in the attractions
table. What relationships would I set up and what would this query look like?
I’ve tried using the "Has Many Through" relationship, but I’m not sure if this applies, as my relationship is between two tables, not three.
I have a table places
, with columns:
id | place_id | name |
---|---|---|
1 | 999 | New York |
2 | 1000 | Miami |
3 | 1001 | Houston |
And a second table, attractions
:
id | place_id | parent_place_id |
---|---|---|
1 | 1000 | 999 |
2 | 1001 | 999 |
2
Answers
Then you can retrieve all places where
parent_place_id
is equal to 999 from the attractions table.Then you can call it with a method like this: