2

I have to create a multilingual table so i choose this schema:

Article ( id, name_translation_fk)

Translation ( id )

Translation_Text (id, language, translation_fk, text)

Now i need to add names in different languages for an article that allready exists. Doctrine gives me this error:


Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be an array, object given, called in */vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php on line 416 and defined in */vendor/doctrine-common/lib/Doctrine/Common/Collections/ArrayCollection.php line 46


I have no clue what the problem could be since all the entities are well declared.I think the issue is somewhere in the Form Class.

I have posted below my entities, forms and views implicated.

Article

 class Article
 {

  /**
   * @ORM\ManyToOne(targetEntity="Translation", inversedBy="article_name", cascade=  {"persist"})
   * @ORM\JoinColumn(name ="name", referencedColumnName="id")
   */
  protected $name;
 }

Translation

class Translation
{

    /**
     * @ORM\OneToMany(targetEntity="Translation_Text", mappedBy="translation", cascade={"persist"})
     */
     public $translation_text;

    /**
    * @ORM\OneToMany(targetEntity="Article", mappedBy="name", cascade={"persist"})
    */
    protected $article_name;      

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

Translation_Text

class Translation_Text
{

/**
 * @ORM\ManyToOne(targetEntity="Language", inversedBy="translation_text")
 * @ORM\JoinColumn(name ="language_id", referencedColumnName="id")
 */
protected $language;

/**
 * @ORM\ManyToOne(targetEntity="Translation", inversedBy="translation_text")
 * @ORM\JoinColumn(name ="translation_id", referencedColumnName="id")
 */
protected $translation;
 }

The form

class TranslationTextType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('text','text');                    
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Udo\WebserviceBundle\Entity\Translation_Text',
        );
    }

    public function getName()
    {
        return 'translation_text';
    }

}

class TranslationType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {            
        $builder->add('translation_text',new TranslationTextType());
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Udo\WebserviceBundle\Entity\Translation',
        );
    }

    public function getName()
    {
        return 'translation';
    }

}

class ArticleTranslationForm extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('name',new TranslationType());
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Udo\WebserviceBundle\Entity\Article',
        );
    }

    public function getName()
    {
        return 'article';
    }
}

The controller

 $article = $em->getRepository('Udo\WebserviceBundle\Entity\Article')->find($id);
 $form = $this->createForm(new ArticleTranslationForm(),$article);

The form view

<form action="{{path('article_translate', { 'id': entity.id }) }}" method="post" {{        form_enctype(form) }}>
{{form_row(form.name.translation_text.text)}}
{{form_rest(form)}}
<input type="submit" />
</form>
1
  • 1
    Ok, I don't get the Entities at all. What you want to do is Article m:n Translation_Text, is that correct? And you want to do it through the Translation class? So what does What does the relation to Language in Translation_Text mean? Commented Nov 2, 2011 at 10:34

1 Answer 1

3

Since it is a ont-to-many relationship, you should use collection:

$builder->add('translation_text', 'collection', array('type' => new TranslationTextType()));

instead of:

$builder->add('translation_text',new TranslationTextType());
Sign up to request clarification or add additional context in comments.

Comments

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.