主义findOneBy(),外键值为空

时间:2019-01-14 01:12:54

标签: symfony doctrine-orm doctrine

我正在用Symfony和Doctrine做博客制作者

我正在尝试连接博客文章中具有blog_id值的评论的行ID,但是当我使用findOneBy()查询某些博客文章时,即使我有数据库中的一些条目。

转储

enter image description here

\ Entity \ BlogPosts.php

class BlogPosts
{
    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Frontend\Blog\Fe_blog_comments", mappedBy="blogId")
     */
    private $comments;

    public function __construct()
    {
        $this->comments = new ArrayCollection();
    }

    //...
}

\ Entity \ Frontend \ Blog \ Fe_blog_comments.php

class Fe_blog_comments
{
    //...

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\BlogPosts", inversedBy="comments")
     * @ORM\JoinColumn(name="blog_id", referencedColumnName="id")
     */
    private $blogId;

    //...
}

编辑: 从控制器查询

$postContent = $entityManager->getRepository(BlogPosts::class)
            ->findOneBy(
                array('postLink' => $link));
dump($postContent->getComments());

探查器理论查询器

SELECT 
  t0.id AS id_1, 
  t0.author_id AS author_id_2, 
  t0.post_time AS post_time_3, 
  t0.edit_time AS edit_time_4, 
  t0.post_content AS post_content_5, 
  t0.post_title AS post_title_6, 
  t0.post_extract AS post_extract_7, 
  t0.post_status AS post_status_8, 
  t0.post_link AS post_link_9, 
  t0.meta_description AS meta_description_10, 
  t0.meta_keywords AS meta_keywords_11 
FROM 
  blog_posts t0 
WHERE 
  t0.post_link = ? 
LIMIT 
  1

0 个答案:

没有答案
相关问题