I am new to Eloquent, and to Laravel actually. I am re-writing a project I built without a framework using the data mapper design pattern.
I am using migrations to build my tables again. A couple of these tables contain foreign key constraints, and others contain references to other tables but are not foreign keys as they are optional.
For example (1), my tasks table has a 'client_id' foreign key referencing clients(id), with cascade delete.
(2) But the tasks table also includes a 'department_id' column, which CAN be NULL, and no cascade action should take place on delete or update (so it's not been set as a foreign key of any sort), but if it is set, I know it references departments(id)
Here's where I'm not sure...
-
Do I need to include the foreign keys in my migrations where there is a cascade action set? Does eloquent/my models need to know about these foreign keys?
-
What about columns like department_id above? Or are these handled by setting the relationships in my models? Obviously they shouldn't be given cascade actions.
-
Say I want to be able to list multiple department_id's, do I create a jointable or does Eloquent take care of this?
Thanks in advance.