Quick question in RoR: Is it possible to have two fields use foreign keys from the same model?
For example, I am an employee. I want two fields: my current shop, and a shop I will be moved to in the future. In my model, how can I have two fields that are both the same foriegn key, but with different values.
It’s hard to explain…
An example
EMPLOYEE TABLE
----------------------------------------------
Name Current Shop ID Next Shop ID
John Doe 2 1
SHOP TABLE
----------------------------
ID Shop Name
1 Jims Tools
2 Johns Tools
In the Employee model, I want both Current Shop and Next Shop to be foreign keys from the Shop model.
1 Answer