【发布时间】:2023-03-11 21:02:02
【问题描述】:
我有一个问题。 我不会通过我的帖子 ID 返回 cmets,但是当我这样做时,我有这个错误:
[Semantical Error] line 0, col 57 near 'post_id = :post_id': Error: Class Ibw\JobeetBundle\Entity\comments has no field or association named post_id
我的comment.orm.yml
Ibw\JobeetBundle\Entity\comments:
type: entity
table: null
repositoryClass: Ibw\JobeetBundle\Entity\commentsRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
comment:
type: text
addDate:
type: datetime
column: add_date
heading:
type: string
length: 255
name:
type: string
length: 255
manyToOne:
postId:
targetEntity: Blog
inversedBy: comments
joinColumn:
name: post_id
referencedColumnName: id
lifecycleCallbacks: { }
我的博客.orm.yml
Ibw\JobeetBundle\Entity\Blog:
type: entity
table: null
repositoryClass: Ibw\JobeetBundle\Entity\BlogRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
title:
type: string
length: 255
text:
type: text
created_at:
type: datetime
author:
type: string
length: 255
image:
type: string
lenght: 255
nullable: true
oneToMany:
comments:
targetEntity: comments
mappedBy: Blog
lifecycleCallbacks:
prePersist: [ preUpload, setCreatedAtValue ]
preUpdate: [ preUpload, setUpdatedAtValue ]
postPersist: [ upload ]
postUpdate: [ upload ]
postRemove: [ removeUpload ]
这是我的方法:
public function getComments($postId) {
$qb = $this->createQueryBuilder('c')
->where('c.post_id = :post_id')
->setParameter('post_id', $postId)
->orderBy('c.add_date', 'DESC');
return $qb->getQuery()->getResult();
}
最后一个代码是,我返回帖子的方法和 cmets:
public function showAction($id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('IbwJobeetBundle:Blog')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Blog entity.');
}
$comments = $em->getRepository('IbwJobeetBundle:comments')
->getComments($id);
$image = $entity->getWebsPath();
return $this->render('IbwJobeetBundle:Blog:show.html.twig', array(
'entity' => $entity,
'image' => $image,
'comments' => $comments
));
}
所以我不知道为什么它不起作用,请帮助某人。
【问题讨论】:
标签: php symfony orm doctrine-orm