2

I have 3 entity that have a relation to each other. My entities are:

  1. OPTION
  2. PLAN
  3. PRICE

Relationships:

  • PLAN and OPTION have a many-to-many relationship
  • Map of PLAN and OPTION has a many-to-many relation with PRICE

any plan has some options. an option of one plan has some price.

My possible solutions:

  • I can create an PLAN_OPTION_MAP table and then map it with PRICE and create PLAN_OPTION_MAP_PRICE_MAP table. Solution 1
  • I can create an PLAN_OPTION_PRICE_MAP table with id of all 3 tables that primary key is made by composite of them

Which is the better solution?

  • What does to map a table with another table mean? – miracle173 Aug 1 '15 at 14:36
  • 1
    hi @miracle173. please read en.wikipedia.org/wiki/Junction_table . – iman Aug 2 '15 at 4:16
  • The second Relationship bullet seems incorrect to me, but I'm guessing as you do not explain your business meaning. If options are the pieces that make up a plan, then I imagine it is only options that have a price. A plan’s cost is merely the sum of its constituent options’ price. As that sum can be calculated, it means there is no relationship between plan and price. If this is not the case I suggest you explain a more of the business problem. – Basil Bourque Aug 4 '15 at 3:53
  • Also, I wonder why Price is a table. Can you explain, or give some of its columns? – Basil Bourque Aug 4 '15 at 3:55
  • @Basil Bourque, price is a table because you can create multi price list for any plan. any plan have some options and every option of a plan must have a price from a price list. – iman Aug 4 '15 at 6:13
1

I think the first solution is good when you know that some instances WOULD NOT participate in relation. But what about second solution? I think it's good when you're sure that all of the instances WOULD participate in relation. The first thing you can do, is analyzing your Problem.

  • hi @sajastu. i know all instances would participate in relation. – iman Aug 2 '15 at 4:12
1

You can have any combination of Plan and Option. Fine. Now here's the question: does a given combination of (P,O) have a given Price? As the three-way intersection table is one of your answers, that would seem to be the case.

Perhaps it would be clearer to think of it like this. An intersection table has two keys that relate to (generally) two different tables which defines a many-to-many relationship between the entities represented by those tables. Any additional fields defined in the intersection table are attributes of the relationship itself, not of either of the entities. For example, the date the relationship was formed.

In your case, price would seem to be an attribute of the relationship (P,O). ("The combination of this Plan with this Option has a price P.") This could, of course, be a FK reference of its own, but that makes me wonder about the makeup of a Price row. Price would seem to be a fairly atomic value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.