duanaozhong0696 2016-02-05 10:02
浏览 60
已采纳

将Vehicle Entity连接到ProductinOrder实体中的Product Entity

I'm building a shop for a roadhelp company an I'm stuck on how to connect two of my Entities in the best way.

Here is a brief summary of the Entities:

Orders: This is where all the basic order data is. (PK = orderid, ipaddress, etc)

Product: This contains a productid as PK, name, price etc. This can be a subscription to a Roadhelp product but it can also be a showel you buy together with a subscription.

ProductinOrders: This contains foreign keys to Orders and Product. The PK is orderid, productid and weight. It also contains a field for whether or not the product can be removed from the order.

And now for the "bastard"...

I also have a Vehicle Entity where the PK are orderid (from Orders) and Licenseplate. The Entity contains data like Make, Model, Variant etc. (This data is retrieved when the customer enters the licenseplate in the form).

The customer should be able to buy as many subscriptions as he/she wants to in the same "flow". Therefore I need to keep Vehicle and the subscription Product in the ProductinOrders in sync.

To make a long story short... sigh

When the customer as entered the Licenseplate I need to be able to connect the licenseplate with a specific product.

Regards, Lars Hansen

  • 写回答

1条回答 默认 最新

  • douba9654 2016-02-05 11:19
    关注

    My advice is that you should connect your entities like in real world. So: Orders ManyToMany Product, User OneToMany/ManyToMany Vehicle (it depends), Vehicle ManytoMany Product

    You'll be able to find Vehicle for signed User, Products for the specified Vehicle and also Products in the specified Order

    Of course you have to think about updating and persisting both sides of relatinships of entites in your entities methods.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?