Ocramius / ocramius.github.com

:books: Coding thoughts and ideas by Ocramius
https://ocramius.github.io/
40 stars 25 forks source link

Question on Doctrine and Zend Form Annotations for collection properties #1

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hi, I've read up your comments on the Annotations issue on the mailing list http://zend-framework-community.634137.n4.nabble.com/Annotations-own-implementation-or-Doctrine-Commons-td4655427i20.html and hope you can help me out on an issue I've encountered which may or may not be a bug.

Let's say I have a basic persistable blogpost class

use Zend\Form\Annotation;
use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity
 * @Annotation\Hydrator("Zend\Stdlib\Hydrator\ClassMethods")
 * @Annotation\Object("Blogpost")
 */
class Blogpost {
    /**
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="blogpost", cascade={"persist"})
     * @Annotation\ComposedObject("Comment")
     */
    protected $comments;

with some Comment objects as sub-objects.

If I now want to create the Form for this class using the AnnotationBuilder the ComposedObject annotation fails as the $comments variable either contains an ArrayCollection list if it is a new blogpost or a PersistentCollection if it is a blogpost loaded from doctrine. So far I've been unable to resolve this issue if the property is not a simple subobject but a traversable list of objects. I tried to follow Matthew's blogpost http://www.mwop.net/blog/2012-07-02-zf2-beta5-forms.html and combine it with Michael's http://www.michaelgallego.fr/blog/2012/07/04/new-zendform-features-explained/ but no luck. Neither of them could or would reply to my questions. As you work with both frameworks I hope know of a solution for this. If you need more information let me know. Regards, Cris

Ocramius commented 11 years ago

@CrisMKM I personally don't use forms at all, so I may not be very helpful here.

Anyway, a ComposedObject probably cannot handle a collection. Did you try to use the FQCN as annotation parameter?