Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Dear Friends, I've a question about Join with multiple tables.
      I've 3 tables: Country, State, City, and I need get country_name from City Entity.
      Any suggestion?

      Table City:
      city_id
      state_id
      city_name

      Table State
      state_id
      country_id
      state_name

      Table Country
      country_id
      country_name

      This is my Entity City:

      <?php
      
      namespace System\Entity;
      
      use Doctrine\ORM\Mapping as ORM,
      Doctrine\Common\Collections\ArrayCollection;
      
      /**
      
          SysCity
          *
          @ORM\Table(name="sys_city")
          @ORM\Entity(repositoryClass="System\Entity\SysCityRepository")
          */
          class SysCity
          {
          /*
          Instantiate all methods gets and sets
          */
      
      public function __construct($options = null)
      { Configurator::configure($this, $options); }
      
      /**
      
          @var integer
          *
          @ORM\Column(name="id_city", type="integer", nullable=false)
          @ORM\Id
          @ORM\GeneratedValue(strategy="IDENTITY")
          */
          private $idCity;
      
      /**
      
          @var string
          *
          @ORM\Column(name="city", type="string", length=255, nullable=false)
          */
          private $city;
      
      /**
      
          @var \SysState
          *
          @ORM\ManyToOne(targetEntity="System\Entity\SysState", inversedBy="state")
          @ORM\JoinColumns( { * @ORM\JoinColumn(name="id_state", referencedColumnName="id_state") * }
      
          )
          */
          private $idState;
      
      /**
      
          @var \SysCountry
          *
          @ORM\ManyToMany(targetEntity="System\Entity\SysCountry", inversedBy="country")
          @ORM\JoinTable(name="sys_state",
          joinColumns= {@ORM\JoinColumn(name="id_state", referencedColumnName="id_state")}
      
          ,
          inverseJoinColumns= {@ORM\JoinColumn(name="id_country", referencedColumnName="id_country")}
          )
          */
          private $idCountry;
      
      public function getIdCity()
      { return $this->idCity; }
      
      public function setIdCity($idCity)
      { $this->idCity = $idCity; return $this; }
      
      public function getCity()
      { return $this->city; }
      
      public function setCity($city)
      { $this->city = $city; return $this; }
      
      public function getIdState()
      { return $this->idState; }
      
      public function setIdState($idState)
      { $this->idState = $idState; return $this; }
      
      public function getIdCountry()
      { return $this->idCountry; }
      
      public function setIdCountry($idCountry)
      { $this->idCountry = $idCountry; return $this; }
      

      Thanks a lot!

        Activity

        Adriano Crivelari created issue -
        Marco Pivetta made changes -
        Field Original Value New Value
        Description Dear Friends, I've a question about Join with multiple tables.
        I've 3 tables: Country, State, City, and I need get country_name from City Entity.
        Any suggestion?

        Table City:
        city_id
        state_id
        city_name

        Table State
        state_id
        country_id
        state_name

        Table Country
        country_id
        country_name


        This is my Entity City:

        <?php

        namespace System\Entity;

        use Doctrine\ORM\Mapping as ORM,
        Doctrine\Common\Collections\ArrayCollection;

        /**

            SysCity
            *
            @ORM\Table(name="sys_city")
            @ORM\Entity(repositoryClass="System\Entity\SysCityRepository")
            */
            class SysCity
            {
            /*
            Instantiate all methods gets and sets
            */

        public function __construct($options = null)
        { Configurator::configure($this, $options); }

        /**

            @var integer
            *
            @ORM\Column(name="id_city", type="integer", nullable=false)
            @ORM\Id
            @ORM\GeneratedValue(strategy="IDENTITY")
            */
            private $idCity;

        /**

            @var string
            *
            @ORM\Column(name="city", type="string", length=255, nullable=false)
            */
            private $city;

        /**

            @var \SysState
            *
            @ORM\ManyToOne(targetEntity="System\Entity\SysState", inversedBy="state")
            @ORM\JoinColumns( { * @ORM\JoinColumn(name="id_state", referencedColumnName="id_state") * }

            )
            */
            private $idState;

        /**

            @var \SysCountry
            *
            @ORM\ManyToMany(targetEntity="System\Entity\SysCountry", inversedBy="country")
            @ORM\JoinTable(name="sys_state",
            joinColumns= {@ORM\JoinColumn(name="id_state", referencedColumnName="id_state")}

            ,
            inverseJoinColumns= {@ORM\JoinColumn(name="id_country", referencedColumnName="id_country")}
            )
            */
            private $idCountry;

        public function getIdCity()
        { return $this->idCity; }

        public function setIdCity($idCity)
        { $this->idCity = $idCity; return $this; }

        public function getCity()
        { return $this->city; }

        public function setCity($city)
        { $this->city = $city; return $this; }

        public function getIdState()
        { return $this->idState; }

        public function setIdState($idState)
        { $this->idState = $idState; return $this; }

        public function getIdCountry()
        { return $this->idCountry; }

        public function setIdCountry($idCountry)
        { $this->idCountry = $idCountry; return $this; }

        Thanks a lot!
        Dear Friends, I've a question about Join with multiple tables.
        I've 3 tables: Country, State, City, and I need get country_name from City Entity.
        Any suggestion?

        Table City:
        city_id
        state_id
        city_name

        Table State
        state_id
        country_id
        state_name

        Table Country
        country_id
        country_name


        This is my Entity City:

        {code}
        <?php

        namespace System\Entity;

        use Doctrine\ORM\Mapping as ORM,
        Doctrine\Common\Collections\ArrayCollection;

        /**

            SysCity
            *
            @ORM\Table(name="sys_city")
            @ORM\Entity(repositoryClass="System\Entity\SysCityRepository")
            */
            class SysCity
            {
            /*
            Instantiate all methods gets and sets
            */

        public function __construct($options = null)
        { Configurator::configure($this, $options); }

        /**

            @var integer
            *
            @ORM\Column(name="id_city", type="integer", nullable=false)
            @ORM\Id
            @ORM\GeneratedValue(strategy="IDENTITY")
            */
            private $idCity;

        /**

            @var string
            *
            @ORM\Column(name="city", type="string", length=255, nullable=false)
            */
            private $city;

        /**

            @var \SysState
            *
            @ORM\ManyToOne(targetEntity="System\Entity\SysState", inversedBy="state")
            @ORM\JoinColumns( { * @ORM\JoinColumn(name="id_state", referencedColumnName="id_state") * }

            )
            */
            private $idState;

        /**

            @var \SysCountry
            *
            @ORM\ManyToMany(targetEntity="System\Entity\SysCountry", inversedBy="country")
            @ORM\JoinTable(name="sys_state",
            joinColumns= {@ORM\JoinColumn(name="id_state", referencedColumnName="id_state")}

            ,
            inverseJoinColumns= {@ORM\JoinColumn(name="id_country", referencedColumnName="id_country")}
            )
            */
            private $idCountry;

        public function getIdCity()
        { return $this->idCity; }

        public function setIdCity($idCity)
        { $this->idCity = $idCity; return $this; }

        public function getCity()
        { return $this->city; }

        public function setCity($city)
        { $this->city = $city; return $this; }

        public function getIdState()
        { return $this->idState; }

        public function setIdState($idState)
        { $this->idState = $idState; return $this; }

        public function getIdCountry()
        { return $this->idCountry; }

        public function setIdCountry($idCountry)
        { $this->idCountry = $idCountry; return $this; }
        {code}

        Thanks a lot!
        Marco Pivetta made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Resolution Invalid [ 6 ]

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Adriano Crivelari
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: