Domanda

Multiple Voting Table Schema: Multiple Voting Table Schema Single Voting Table Schema: Single Voting Table Schema

Businesses, Products, and Comments can all be voted on. For the first obvious solution, I chose to create an association entity for each of the relationships. We thought maybe there would be a better solution, though.

After extensive research and looking around for a solution, I found the concept of the second schema, which is to have a single voting table with a column (Entity) to define the type of the table or the table in which the ID (EntityID being the ID of the Table it Came From) belongs to. The only problem is that there is no relationship between the voting table and the three entities. Is there a way for the Entity Column to refer to the table rather than the table's ID?

Any suggestions of other constructive ways of developing the schema are welcome.

È stato utile?

Soluzione

I think you will find this answer very sufficient.

Why can you not have a foreign key in a polymorphic association?

What you're looking at here is a Polymorphic Association. It has many solutions, of which three are described thoroughly through the given post.

Altri suggerimenti

I would suggest you combine the Business, Product and Comment tables into a single table, with an additional colume to denote 'Type'. Then you can enforce your relationship to the Vote table.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top