Symfony 2.8の本の例の後半では、初心者の方がManyToOne関係でデータベースからデータを取得するのに問題があります。私はデータベーステーブルカテゴリと1つのを使用しています。 配備は、category_idを持ち、categories.idを指します。そのため、1つのカテゴリには多くのデプロイメントを配置できます。データベースにはデータがあり、pmaでカスタムクエリを実行すると結果が得られます。Symfony 2.8 Doctrineフェッチ/データ表示のトラブル
私の質問:コントローラコードを実行した後、コレクション(画像参照)が表示されますが、展開要素が表示されません。私は間違って何をしていますか?どのように私は私が私のコントローラ内の特定の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