It is not possible due to doctrine's proxies workflow.

I had a discusion like about 30 responses within this mailing list looking
for the same answer, without a practical success.

Doctrine's official docs tells  you can't serialize entities (when they are
proxies).

What I implemented is a backToLife function:

I serialize the owning-side-association Entity/ies in a session var, and
then (to be able to access its related entities) I seek
for them again with the entity_manager, something like:

$entities = unserialize($serializedEntities);

foreach($entities as $entity)
{

  $entity = $entity_manager('Bundle:Entity')->find($entity->getId());
}

This way, entities will be 'attached' back to its real 'form', cause you
won't be able to access a related entity from an unserialized entity
(because, yu have to serialize/unserialize an object to be able to be
stored/retrieve in a session variable).

If you find a better solution, share!

Regards!
2011/6/10 Michael Holm <ho...@hollo.dk>

> Hi,
>
> I have started to build a search function on my website..
>
> My idea was to have a filter form class, give it an object which i
> then will serialize and then save it in a session.. and it works just
> perfect if i have no relationships in the object..
>
> But when i want to make a relation to an another table, that
> relationship will not be serialized.. can some one help? Is it
> possible, or do i have to do it in an another way, here is what i do:
>
>  public function filterAction()
>  {
>    $filter = new \Club\UserBundle\Entity\User();
>
>    $form = $this->createForm(new \Club\UserBundle\Filter\User($filter));
>    $form->bindRequest($this->get('request'));
>
>    if ($form->isValid()) {
>
>  $this->get('session')->set('filter.admin_user',serialize($form->getData()));
>    }
>
>    return $this->forward('ClubUserBundle:AdminUser:index');
>  }
>
> Pretty straight forward, and when i want to load the form i simple
> does unserialize the object and load it with setData()..
>
>  public function indexAction()
>  {
>    $em = $this->get('doctrine')->getEntityManager();
>
>    $filter = unserialize($this->get('session')->get('filter.admin_user'));
>    $filter = ($filter instanceOf \Club\UserBundle\Entity\User) ?
> $filter : new \Club\UserBundle\Entity\User();
>
>    $filter_form = $this->createForm(new \Club\UserBundle\Filter\User());
>    $filter_form->setData($filter);
>
> Can someone give me a hint, or maybe have a better solution for
> creating search functionality?
>
> Best regards,
> Michael Holm
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to