Search code examples
databaseumlclass-diagramerd

UML confusion on Many to Many scenario


This is my sample class diagram

cls_Invoice = {InvoiceID:int, InvoiceDate:Date, InvoiceProduct:cls_Products};

cls_Products = { ProductID:int, StockQuantity:double , Price:double};

DB tables

Invoice = { InvoiceID, InvoiceDate}; Products = { ProductID, StockQuantity, Price};

1 Invoice has Many Products 1 Products can be in Many Invoices so eventually there will be a linking in ER design as shown below

Invoice_Products = {InvoiceID, ProductID, Qty, Price}

but now there are another two properties Qty and Price which I have no idea on drawing the class diagram please advice ?


Solution

  • In a UML class diagram, you'd have two classes: Invoice and Product. Invoice has two attributes: InvoiceID and InvoiceDate, Product has three attributes: ProductID, StockQuantity, and Price. Between the two classes you need an association, with a multiplicity of 1..* on both ends.