I am trying to model the following table structure in Symfony 2.0 using annotations.
State
PK Code
Name
County
PK State_Code -> FK State.Code
PK Code
Name
Muni
PK State_Code -> FK.State.Code
PK County_Code -> FK County.Code
PK Code
Name
Modeling the fields and the state – county relationship is simple enough, but I cannot determine how to define the relationship for the Muni table.
- States have one or more counties.
- Counties have one or more Munis.
- Munis belong to one or more Counties.
The table structure is legacy and cannot be modified.
Here you go. Tested with Symfony 2.0.5 (Doctrine 2.1):
State.php
County.php
Muni.php
Don’t forget to generate getters/setters. All relationships are bi-directional.