1

Doctrine2でそれが可能になることを願っています。Propel が自動的にそれを行うことは知っています。私がやりたいことはこれです:

私は2つのテーブルを持っています:

workflow (id, name)
inbox (id, workflow_id, name)

および 2 つのエンティティ:

Workflow and Inbox

もちろん、受信トレイ エンティティには次のようなものがあります (2 つのテーブルを関連付けるため):

  /**
   * @ORM\ManyToOne(targetEntity="Workflow")
   * @ORM\JoinColumn(nullable=false)
   */
  protected $workflow;

すべてがうまく機能します。ただし、そのワークフローに関連付けられているワークフロー エンティティから受信トレイを取得できるようにしたいと考えています。方法が見つかりません。

Propel はそれを非常に簡単に行います。次のようにするだけです:

$workflow = WorkflowQuery::create()
  ->filterById(1)
  ->findOne(1);

$inboxes = $workflow->getInboxs() 
//Propel just addes 's' to methods that return associations

どうやって Doctrine2 でこれを行うことができますか? このようなもの:

$workflow = $this->getRepository('MyBundle:Workflow')->findById(1);
$inboxes = $workflow->getInboxes();

それで、これを行う方法はありますか?ありがとうございました。

4

1 に答える 1

2

コントローラーの変更:

$workflow = $this->getDoctrine()->getRepository('MyBundle:Workflow')->find(1);
$inboxes = $workflow->getInboxes();

必要であることを忘れないでください

// Workflow entity
public function __construct()
{
    // make `use` statement for this, not long
    $this->inboxes = new \Doctrine\Common\Collections\ArrayCollection() ;
}

/**
* @ORM\OneToMany(targetEntity="Inbox", mappedBy="workflow", cascade={"persist"})
*/
protected $inboxes ;
public function getInboxes() { return $this->inboxes ; }
// setInboxes(), addInbox(), removeInbox() here
于 2013-06-06T13:12:02.080 に答える