Sf2 // Object of class… could not be converted to string on relation

I have two entities “category.php” and “subCategory.php” with a correct manyToOne relation on subCategory.php to category.php, like this.

    /**
     * @var integer
     *
     * @ORM\Column(name="categoryId", type="integer")
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $categoryId;

When saving a form I have the error “Object of class… could not be converted to string”.

This error occured because when specifying a relation (manyToOne, oneToMany, oneToOne, etc…), you have no need of specifying “@ORM\Column” again, because the property is already mapped by the relation.

The answer is:

    /**
     * @var integer
     *
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $categoryId;
Advertisements
Sf2 // Object of class… could not be converted to string on relation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s