Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:54:18+00:00 2026-05-26T17:54:18+00:00

I am trying to model the following table structure in Symfony 2.0 using annotations.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:54:18+00:00Added an answer on May 26, 2026 at 5:54 pm

    Here you go. Tested with Symfony 2.0.5 (Doctrine 2.1):

    State.php

    namespace Acme\WhateverBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * State
     *
     * @ORM\Entity
     */
    class State
    {
        /**
         * @ORM\Id()
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\Column(name="Code", type="integer")
         */
        private $code;
    
        /**
         * @ORM\Column(name="Name", type="string")
         */
        private $name;
    
        /**
         * @ORM\OneToMany(targetEntity="County", mappedBy="state_code")
         */
        private $counties;
    
        /**
         * @ORM\OneToMany(targetEntity="Muni", mappedBy="state_code")
         */
        private $munis;
    }
    

    County.php

    namespace Acme\WhateverBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * County
     *
     * @ORM\Entity()
     */
    class County
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\Column(name="Code", type="integer")
         */
        private $code;
    
        /**
         * @ORM\Column(name="Name", type="string")
         */
        private $name;
    
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\ManyToOne(targetEntity="State", inversedBy="counties")
         * @ORM\JoinColumn(name="State_Code", referencedColumnName="Code")
         */
        private $state_code;
    
        /**
         * @ORM\OneToMany(targetEntity="Muni", mappedBy="county_code")
         */
        private $munis;
    }
    

    Muni.php

    namespace Acme\WhateverBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Muni
     *
     * @ORM\Entity
     */
    class Muni
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\Column(name="Code", type="integer")
         */
        private $code;
    
        /**
         * @ORM\Column(name="Name", type="string")
         */
        private $name;
    
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\ManyToOne(targetEntity="County", inversedBy="munis")
         * @ORM\JoinColumn(name="County_Code", referencedColumnName="Code")
         */
        private $county_code;
    
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="NONE")
         * @ORM\ManyToOne(targetEntity="State", inversedBy="munis")
         * @ORM\JoinColumn(name="State_Code", referencedColumnName="Code")
         */
        private $state_code;
    }
    

    Don’t forget to generate getters/setters. All relationships are bi-directional.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a mapping file for the following Model using Fluent
I have the following table structure: I'm trying to populate a combobox of all
I have the following django model (mapped to table 'A'): class A(models.Model): name =
Using MVC3 I am trying to accomplish the following. I have a table which
I have the following code, I'm trying to get a table with 4 columns
I am developing an application using Hibernate and am trying to model the following
I have the following DB model: **Person table** ID | Name | StateId ------------------------------
I have the following domain model setup using EF code first: public class User
I'm trying to create a Django model that handles the following: An Item can
I'm trying to do something like the following: @special_attributes = Model.new.methods.select # a special

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.