Is there a way to define reference name with "rails generate" command?
There is table A with two fields - a1 and a2: references to table B.
Is there a way to define reference name with "rails generate" command?
There is table A with two fields - a1 and a2: references to table B.
One of the main principles of rails is "convention over configuration". It works great for cases like this:
This will create column
team_id
and mark it as foreign key to tableteams
.This covers 90% of all possible needs (educated guesstimate). If you have a "standard" model, you'll generate the boilerplate for it in seconds. But if you have a more exotic case (like the one in the question), then you'll have to do a bit of manual work and touch migration file and model relation definitions yourself. Which is quite easy as well.