do i need to create foreign key in migration to let has_many belong_to work?
Can i don’t create any foreign key such as :options => “CONSTRAINT fk_box_storage REFERENCES box(id)” and still have use has_many and belong_to in model?
do i need to create foreign key in migration to let has_many belong_to work?
Share
No need to, if you are only going to have a web app accesing the database. In case you want to access the db with another app or directly I would recommend you DO create the foreign keys since they will give you a better insight of what is going on there and won’t let you insert wrong information or delete by error (in case you set up the on delete option)