Laravel/Eloquent MySQL relationship 1:n and 1:1 help needed
I'm building an app for a digital marketing agency to automate advertising campaign submission and tracking for clients. I'm having trouble wrapping my head around what relationships I need based on the current manual process. I'm the only developer working on this project so I feel like I'm sitting on an island out in the ocean. lol The way the process works now is we have a client prospect, a contract is created, if the prospect/client approves the process goes to the on-boarding/discovery phase followed by the campaign creation and insertion order creation.
The way I have my relationships set up so far is like this:
-
Client table has a 1:n relationship with the contracts table.
-
Contracts, discovery and insertion orders table has a 1:1 relationship with the campaigns table.
-
Contracts table has an foreign key for both the client and campaigns table.
-
Campaigns table has a foreign key for the Client table.
I created an ERD in MySQL Workbench. It shows identifying and non-identifying 1:1 and 1:n. Should I be concerned with these?
As far as the models go, I currently have:
In the Client model:
- contracts hasMany(Contract::class)
- campaigns hasMany(Campaigns::class)
In the Campaign model, I have:
- client - belongsTo(Client::class)
In the Discovery and Insertion Order models:
- campaign - belongsTo(Campaign::class)
In the Contract model:
- client - belongsTo(Client::class)
- campaign belongsTo(Campaign::class)
If you need additional information, please let me know.
Know of any resources, tutorials, etc that might help shed more light on this?
Please or to participate in this conversation.