간단한 질문이 있습니다.많은 게시물과 카테고리에 많은 테이블이 두 개 있습니다. 이 그대로 형태로 나타납니다. PostType 양식 CategoryType의 컬렉션이지만 여기에서 문제가 시작됩니다. . Symfony2 간단한 다 대다 이슈
는 난 그냥 원하는 결과를 얻을하지 않습니다 데이터를 유지하기 위해 요리 책 수집 양식의 지시에 따라 .. 이 여기에 코드입니다 :class Post
{
/**
*
* @ORM\ManyToMany(targetEntity="Categories", inversedBy="posts", cascade={"persist", "remove"})
* @ORM\JoinTable(name="AnCat",
* joinColumns={
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="categories_id", referencedColumnName="id")
* }
*)
**/
protected $categories;
public function __construct()
{
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addCategory($categories)
{
foreach ($categories as $category) {
$category->addPosts($this);
}
$this->categories[] = $categories;
}
class Categories
{
/**
*
* @ORM\ManyToMany(targetEntity="Post", mappedBy="categories")
*/
protected $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
/**
*
* @param Post $post
* @return Categories
*/
public function addPosts(Post $posts)
{
// I tried it but I get the same result!
/*if (!$this->posts->contains($posts)) {
$this->posts->add($posts);
}*/
$posts->addCategory($this);
$this->posts[] = $posts;
}
class PostType extends AbstractType
{
->add('Categories', 'collection', array('type' => new CategoriesType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => '__categ__',
'by_reference' => false
))
class CategoriesType extends AbstractType
{
->add('category', 'entity', array(
'attr' => array('class' => 'cat'),
'class' => 'MyBusinessBundle:Categories',
'property' => 'category',
'label' => 'Categories'
))
문제는 새로운 분야 카테고리를 삽입 카테고리 대신 간단한 관계를 만드는 대신 내가 틀렸다 곳 내가 .. 당신의 postType에서
What와 what? – Hast
어떤 의미입니까? 더 구체적으로 기재 할 수 있습니까? 정보가 누락 된 것 같지 않습니다 ... – Lughino