我正在开发具有Symfony2的项目管理系统。我有一个可以有一个或多个类别(许多2个经济关系)的项目。在使用Symfony生成两个实体,表单和控制器之后,我可以创建一个新类别并为其分配一些项目(类别Project/1/Edit),但我无法执行Oposit,这意味着我无法将类别分配给项目在我的项目编辑表单中(每次我选择某些类别并按更新时,选择的字段再次变白)。怎么可能?这是我的代码:
项目实体:dbe ddbundle entity project:
manyToMany:
categoryProject:
targetEntity: DbeDDBundleEntityCategoryProject
mappedBy: project
类别项目学说:
manyToMany:
project:
targetEntity: DbeDDBundleEntityProject
inversedBy: categoryProject
joinTable:
name: ProjectToCategoryProject
joinColumns:
category_project_id:
referencedColumnName: id
nullable: false
inverseJoinColumns:
project_id:
referencedColumnName: id
nullable: false
这是我从Symfony工具栏中获得的查询:为什么有一个问题标志?
SELECT
t0.id AS id1,
t0.name AS name2,
t0.description AS description3
FROM
CategoryProject t0
INNER JOIN ProjectToCategoryProject ON t0.id = ProjectToCategoryProject.category_project_id
WHERE
ProjectToCategoryProject.project_id = ?
和此处添加函数:
/**
* Add categoryProject
*
* @param DbeDDBundleEntityCategoryProject $categoryProject
* @return Project
*/
public function addCategoryProject(DbeDDBundleEntityCategoryProject $categoryProject)
{
$categoryProject->addCategory($this);
$this->categoryProjects[] = $categoryProject;
// $this->categoryProject[] = $categoryProject;
return $this;
}
预先感谢您的帮助!
这是解决方案,我在推理中犯了一些错误: - )
$entity = $em->getRepository('DbeddddBundle:Project')->findOneById($id);
$comment = $em -> getRepository('DbeDddddBundle:Comment') -> findByProject($entity);