I'm using an ORM (Propel) and PHP to create Objects and store them in a database. So, I'm facing a recurrent problem and I'm pretty sure this happened to someone before.
My data model looks something like this:
So class A needs a reference to something from the hierarchy of
Clase Parent (abstract class), this is not the problem. The idea behind this solutions is that in the future it would be very easy to create new strategies. But remember I said I'm using an ORM to store info in the database?
Well, the database has 3 tables:
C_table. So here comes the situation:
A_table needs to be related to the strategy. Whats the best way to go?
- Create a strategy type reference table, assosiate a type to the A_table and have a relation_id thats just an intenger with a value (no referential integrity whatsoever)
- Create one field per strategy in the A_table, and allow them to be null
Really looking forward for opinions and why its best one or the other.