druhoytza979667566 2015-01-05 13:53
浏览 71
已采纳

学说一对一关系映射

i have two entities that i would like to map them so that when i generate crud for each entity when i want to make a new insert using Map entity to be able to select based on id from Board entity. I've been trying to make the mapping yet .. i didn't manage not sure if i did it right or not because in mysql i don't see a foreign key after sql generation.

Board.php

    <?php

    namespace AppBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**
     * Board
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="AppBundle\Entity\BoardRepository")
     */
    class Board
    {
        /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @ORM\ManyToOne(targetEntity="Board")
         * @ORM\JoinColumns({
         *   @ORM\JoinColumn(name="id", referencedColumnName="BoardId")
         * })

         */
        private $id;

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

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

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

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

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


        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }

        /**
         * Set propertyName
         *
         * @param string $propertyName
         * @return Board
         */
        public function setPropertyName($propertyName)
        {
            $this->propertyName = $propertyName;

            return $this;
        }

        /**
         * Get propertyName
         *
         * @return string 
         */
        public function getPropertyName()
        {
            return $this->propertyName;
        }

        /**
         * Set propertyDescription
         *
         * @param string $propertyDescription
         * @return Board
         */
        public function setPropertyDescription($propertyDescription)
        {
            $this->propertyDescription = $propertyDescription;

            return $this;
        }

        /**
         * Get propertyDescription
         *
         * @return string 
         */
        public function getPropertyDescription()
        {
            return $this->propertyDescription;
        }

        /**
         * Set propertyPicture
         *
         * @param string $propertyPicture
         * @return Board
         */
        public function setPropertyPicture($propertyPicture)
        {
            $this->propertyPicture = $propertyPicture;

            return $this;
        }

        /**
         * Get propertyPicture
         *
         * @return string 
         */
        public function getPropertyPicture()
        {
            return $this->propertyPicture;
        }

        /**
         * Set propertyGlyphonic
         *
         * @param string $propertyGlyphonic
         * @return Board
         */
        public function setPropertyGlyphonic($propertyGlyphonic)
        {
            $this->propertyGlyphonic = $propertyGlyphonic;

            return $this;
        }

        /**
         * Get propertyGlyphonic
         *
         * @return string 
         */
        public function getPropertyGlyphonic()
        {
            return $this->propertyGlyphonic;
        }

        /**
         * Set propertyPrice
         *
         * @param string $propertyPrice
         * @return Board
         */
        public function setPropertyPrice($propertyPrice)
        {
            $this->propertyPrice = $propertyPrice;

            return $this;
        }

        /**
         * Get propertyPrice
         *
         * @return string 
         */
        public function getPropertyPrice()
        {
            return $this->propertyPrice;
        }
    }

Map.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Map
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AppBundle\Entity\MapRepository")
 */
class Map
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     * @ORM\Column(name="BoardId", type="integer")
     */
    private $boardId;

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

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


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set boardId
     *
     * @param integer $boardId
     * @return Map
     */
    public function setBoardId($boardId)
    {
        $this->boardId = $boardId;

        return $this;
    }

    /**
     * Get boardId
     *
     * @return integer 
     */
    public function getBoardId()
    {
        return $this->boardId;
    }

    /**
     * Set x
     *
     * @param string $x
     * @return Map
     */
    public function setX($x)
    {
        $this->x = $x;

        return $this;
    }

    /**
     * Get x
     *
     * @return string 
     */
    public function getX()
    {
        return $this->x;
    }

    /**
     * Set y
     *
     * @param string $y
     * @return Map
     */
    public function setY($y)
    {
        $this->y = $y;

        return $this;
    }

    /**
     * Get y
     *
     * @return string 
     */
    public function getY()
    {
        return $this->y;
    }
}
  • 写回答

1条回答 默认 最新

  • dongyijing2353 2015-01-05 14:13
    关注

    It seams like you haven't read the manual. It is great documentation on both Symfony.com and Doctrine-orm.readthedocs.org.

    Read this article (http://symfony.com/doc/current/book/doctrine.html) and use this one as reference (http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html) and you will find the answer to this and many future questions.

    What you basically need to do is:

     class Board {
       /**         
        * @ORM\ManyToOne(targetEntity="Map")
        */
       private $map;
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题