대부분의 경우 Symfony 2.8 서적 예제를 따르면 초보자로서 ManyToOne 관계로 데이터베이스에서 데이터를 가져 오는 데 문제가 있습니다. 데이터베이스 테이블이 이고 은입니다. 배포에는 category_id이 있으며 categories.id을 나타냅니다. 그래서 하나의 카테고리는 많은 배치를 가질 수 있습니다. 데이터베이스에는 데이터가 있는데, Pma에서 사용자 정의 쿼리를 실행하면 결과가 표시됩니다.Symfony 2.8 Doctrine 가져 오기/표시 데이터 문제
내 질문 :내 컨트롤러 코드를 실행 한 후 Collection (이미지 참조)을 얻었지만 deploy 요소로 채워지지 않았습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 내가 배포 특정 CATEGORY_ID을 가진 요소 내 컨트롤러에서
를 표시 할 수 있습니다 어떻게 수행
$category = $this->getDoctrine()->getRepository('AppBundle:Category')->find(1);
$deploys = $category->getDeploys();
dump($deploys);
die();
내가 가지고 배포 엔티티 (그것의 일부를 응용 프로그램/콘솔)
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="deploys")
*/
class Deploy {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="deploys")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
private $category;
// etc
그리고 분류 엔티티에 의해 생성되었습니다
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="categories")
*/
class Category {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer", length=10)
*/
private $weight;
/**
* @ORM\OneToMany(targetEntity="Deploy", mappedBy="category")
*/
private $deploys;
/**
* Constructor
*/
public function __construct() {
$this->deploys = new ArrayCollection();
}
// etc
감사합니다. 작동하도록했습니다. – vaultboy