当前位置: 动力学知识库 > 问答 > 编程问答 >

Symfony2 forms embed mongodb document into sql entity

问题描述:

I need little help :). Here is the situation. I am using symfony2 + FOSUserBundle, I made my forms custom, so far so good. I have User registration with user information in the custom registration form (like first name, last name, birth date etc). Now I decided that it will be more practical to make the user info to be stored in mongodb as document (as I probably will add more information to users later). I built the user info form, and successfully embedded it to the user form. Now the problem is that I cannot set Document object inside Entity object - symfony tells me that the object must be an Entity.

/**

* Acme\UserBundle\Entity\User

*

* @ORM\Table(name="user")

* @ORM\Entity

*/

class User extends BaseUser

{

/**

* @Assert\Type(type="Acme\UserBundle\Document\UserInfo")

*/

protected $userinfo;

I want to ask, what is the proper way to do this ? Sure I can get the needed information form the request as an array and fill in the user info object ... but it looks ugly and wrong :) so how it must be done ? Thanks.

网友答案:

I assume you extends the entity class

FOS\UserBundle\Entity\User

there is a document class provided by the bundle

FOS\UserBundle\Document\User

You could extends this one

分享给朋友:
您可能感兴趣的文章:
随机阅读: