2012-02-16 11 views
0

イムを作り、それはだが、非常によく動作しますが、私はフィールドで、例えばエントリのような別のテーブルを作成する必要があります。FOSUserBundle Symfony2のでFOSUserBundleを使用して自分自身のテーブルとの関係

user_id, description,... 

私はとの関係を確認する必要がありuserテーブルとEntryテーブルです。 One to Manyの関係を作る最良の方法は何ですか?どのクラスを拡張すべきですか?

私はこのエラーを取得する:

Entry has no association named ApplicationSonataUserBundle:User

私のコードは次のとおりです。

/** 
* 
* @ORM\ManyToOne(targetEntity="\Application\Sonata\UserBundle\Entity\User", inversedBy="entry") 
* @ORM\JoinColumn(name="user_id", referencedColumnName="id") 
*/ 

protected $users; 

私はこのinstruccionを使用します。

$em = $this->getDoctrine()->getEntityManager(); 
$query = $em->createQuery('SELECT b 
           FROM LoggerFrontendBundle:Entry a JOIN a.ApplicationSonataUserBundle:User b 
         ') ; 

おかげ

答えて

0

コントローラ

$em = $this->getDoctrine()->getEntityManager(); 
// when you query users, you get the information from the new Entity. 
$users = $em->getRepository('ApplicationSonataUserBundle:User')->findAll(); 

return array('users' => $user); // return the array of user information 

小枝から

/** 
* @ORM\OneToOne(targetEntity="path to User Entity", inversedBy="name") 
*/ 
protected $user; 

:ユーザエンティティ:

/** 
* @ORM\OneToOne(targetEntity="path to new Entity", mappedBy="user", cascade={"persist"}) 
*/ 
protected $name; 

新規エンティティ

{% for user in users %} // loop through users<br/> 

{{ user.name.getName }} // you can call user.getname or user.getEmail , you can add the name from the Entity on and get the fields from the new Entity like user.name.getName etc... 

{% endfor %} //end loop 
+0

[OK]を、私はそれを試してみたので、私は私の質問を更新していますしかし、私は動作しません – JERC

関連する問題