samedi 11 juillet 2020

How tor implement a Database Master-Detail into a Class Model

i'm new to programming with MVC/MVVT. I usually created a software using what i called 'standard' design pattern which is first I created the database then i accessed the database in the program logic and process it (what at the modern days called as the controller (or view in mvvt)). Now the problem is when I looked at MVVT or MVC design pattern, the developer tend to create a class as the 'model' and then used an orm to migrate it to the dbserver (create the table etc.). My question is, when I want to implement some master-detail database design, should i created 2 kind of model class represent each master-detail table? If yes, what about the connection, how it implemented actually? While in database standard design i could just flag fields that i assume as the foreign key, how to make it work in model class?

Assume i've tables master-detail of product such this:

mSalesOrder { SOID (pk), TimeCreation, SalesID (fk), CustomerID (fk), Status, GlobalDiscInPct, GlobalDiscInAmt, VAT, GrandTotal, Note, DeliveryDeadline, DeliveryAddress, DeliveryContactPerson }

dSalesOrder { SOID (pk/fk), PID (pk/fk), qty, BasePrice, DiscInPct, DiscInAmt, NettPrice, TotalAmount, Note }

If the answer is No, then am I need to create just a single Class Model (i.e SalesOrder Class, consist of all fields except the redundant SOID)? unless the orm mapper split it automatically as 2 tables, all fields in the master table will be very redundant...

Cmiiw with my messed concept since i've not been into programming for the last 12 year. Thanks in advanced for your kindly help and reply!

Aucun commentaire:

Enregistrer un commentaire