Symfony 2.8.7学说加入注释不起作用

时间:2016-06-16 12:09:56

标签: php symfony orm doctrine-orm

我遇到了symfony 2.8.7的问题,为了在两个表'users'和'post'之间进行简单的连接和doctrine注释我已经创建了一些实体文件,所以首先是用户实体:

<?php

namespace Blog\FrontBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * user
 *
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="Blog\FrontBundle\Repository\userRepository")
 */
class user
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var post
     * 
     * @ORM\OneToMany(targetEntity="post", mappedBy="user")
     * @ORM\JoinColumn(onDelete="CASCADE")
     */
    private $post;


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

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

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

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_born", type="date")
     */
    private $dateBorn;


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

    /**
     * Set username
     *
     * @param string $username
     *
     * @return user
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

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

    /**
     * Set emailUser
     *
     * @param string $emailUser
     *
     * @return user
     */
    public function setEmailUser($emailUser)
    {
        $this->emailUser = $emailUser;

        return $this;
    }

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

    /**
     * Set passwd
     *
     * @param string $passwd
     *
     * @return user
     */
    public function setPasswd($passwd)
    {
        $this->passwd = $passwd;

        return $this;
    }

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

    /**
     * Set dateBorn
     *
     * @param \DateTime $dateBorn
     *
     * @return user
     */
    public function setDateBorn($dateBorn)
    {
        $this->dateBorn = $dateBorn;

        return $this;
    }

    /**
     * Get dateBorn
     *
     * @return \DateTime
     */
    public function getDateBorn()
    {
        return $this->dateBorn;
    }
}

和邮政实体:

<?php

namespace Blog\FrontBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * post
 *
 * @ORM\Table(name="post")
 * @ORM\Entity(repositoryClass="Blog\FrontBundle\Repository\postRepository")
 */
class post
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\ManyToOne(targetEntity="user", inversedBy="post")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    private $user;

    /**
     *
     * @ORM\OneToMany(targetEntity="comment", mappedBy="post")
     * @var comment
     */
    private $comment;

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

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_post", type="date")
     */
    private $datePost;

    /**
     * @var string
     *
     * @ORM\Column(name="content_post", type="text")
     */
    private $contentPost;


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

    /**
     * Set title
     *
     * @param string $title
     *
     * @return post
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

    /**
     * Set datePost
     *
     * @param \DateTime $datePost
     *
     * @return post
     */
    public function setDatePost($datePost)
    {
        $this->datePost = $datePost;

        return $this;
    }

    /**
     * Get datePost
     *
     * @return \DateTime
     */
    public function getDatePost()
    {
        return $this->datePost;
    }

    /**
     * Set contentPost
     *
     * @param string $contentPost
     *
     * @return post
     */
    public function setContentPost($contentPost)
    {
        $this->contentPost = $contentPost;

        return $this;
    }

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

结果不会获取与用户关联的帖子,我在控制台中看到查询没有进行连接查询:

SELECT 
u0_.id AS id_0, 
u0_.username AS username_1, 
u0_.email_user AS email_user_2, 
u0_.passwd AS passwd_3, 
u0_.date_born AS date_born_4 
FROM 
user u0_

你觉得我错过了什么?感谢您的帮助,我是Symfony的新手

0 个答案:

没有答案