Home » Php » How to better structure a DB for this need?

How to better structure a DB for this need?

Posted by: admin October 26, 2017 Leave a comment


I am programming a web financial app in Symfony.
I have a Entity Loan in database, that is the main object of study. A Loan can also have deferrals, charges and forced payments. So, they are also Entities linked to main entity -> Loan.
Now, I need to implement some “containers”. I need to make a Entity “more superior” than Loan.
Actually, the main object must be a Case. Case it’s kind of : Case John Doe.
John Doe can have more than one loan. So, every loan is a “line of loan”.
Each line of loan can have “regoneciations”. In that situation, this line of loan is calculated in 2 or more separated loans, and in fact they all must append to line of loan.

So, hierarchicaly, it must looks like :
Case > Line of loan > Loan
One case can have many line of loans, and one line of loan can have more than one loan.

Relationship : Case – one to many with Line of loan ; Line of loan – one to many with Loan.
It’s all right with this?

I wanna know from the code side, if this relation will permit me to display at index page all the cases like

Case Name : John Doe
All calculations :
1. Line of loan 1: /loan/3, /loan/4, loan/5
2. Line of loan 2: /loan/6, /loan/7
3. Line of loan 3: /loan/11

Case name : Johny Deep

So, I’m thinking that I will have an action in the controller, like /viewCase/{id} where I will pass the ID of the Case
1. Take from DB all the loans where case_id = {id}
2. Group somehow all this loans by lineOfLoan_id
3. At view page with foreach loop output them ASC

How do you think, it will work?