doutuo3899 2014-01-21 10:28
浏览 57

在Doctrine中获取部分选择的映射字段

I have a post entity which may represent the Post or Comment to another post.

/**
 * @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
 */
private $post;
public function setPost($post) { $this->post = $post; return $this; }
public function getPost() { return $this->post; }

/**
 * @ORM\OneToMany(targetEntity="Post", mappedBy="post", cascade={"remove"})
 */
private $comments;
public function getComments() { return $this->comments; }
....

So normally i can get parent Post by ->getPost();.

Now i want to optimize request and using partial select like this one

$query = $this->getEntityManager()
->createQuery(
    "SELECT partial post.{id, title, Post}
    FROM XXXMyBundle:Post post
    ORDER BY post.id ASC
    ")

But each time i see errors like

There is no mapped field named 'Post' on class

I tried to change field name in query to post_id, post or postId but it didn't help.

Is there any way to get the post_id (that's name of the field in database) ?

  • 写回答

1条回答 默认 最新

  • douwei2825 2014-01-21 10:40
    关注

    OK, thanks to this question i solved my problem.

    "SELECT partial post.{id, title}, partial p.{id}
                 FROM XXXMyBundle:Post post
                 LEFT JOIN post.post p
                 ORDER BY post.id ASC
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度