1

I have created 2 entities
User and Photo

Now I want to create one-to-many relation.
Suppose I have this code in the User entity class:

// User.php
     /**
     * @ORM\OneToMany(targetEntity="Photo", mappedBy="user")
     */
    protected $photos;

    public function __construct()
    {
        $this->photos = new ArrayCollection();
    }

when i add the photo's form into user's form, similarly to how it's done in this code

// UserType.php
    public function buildForm(FormBuilder $builder, array $options)
    {
        // ...
        $builder->add('photos', new PhotoType());
    }

it throws:

Expected argument of type "Acme\UserBundle\Entity\Photo", "Doctrine
\Common\Collections\ArrayCollection" given

so how can I add photo's form into user's form?

ps sorry for my english

1
  • molecule i not uderstand ? what u want say me? Commented Mar 4, 2012 at 10:27

1 Answer 1

3

You are mistaken in your form builder : you need a collection of PhotoType:

$builder->add('photos', 'collection', array('type' => new PhotoType()));

Sign up to request clarification or add additional context in comments.

1 Comment

What is the equivalient of "type" for symony 3?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.