Tag table has a relation to the Category table as Many-to-One (many tags are related to one category, or one category has many tags).
I should get normal Many-to-One relation from table Tag to the table Category. It should be based on the ID from the table Category (which is named id_category). However, instead I’m getting… a VARCHAR(255) column in table Tag!
Here’s part of code from Tag entity:
/**
* @ORM\Column(nullable=true)
* @ORM\ManyToOne(targetEntity="Category")
* @ORM\JoinColumn(name="id_category", referencedColumnName="id_category")
*/
protected $category;
Category entity doesn’t have appropriate related “tag” column, because it’s uni-directional relation. Anyway, here’s how id_category is declared in the Category entity (though I don’t think it’s important):
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id_category;
The result I’m getting by the Doctrine2’s command update --dump-sql is the following:
ALTER TABLE Tag ADD category VARCHAR(255) DEFAULT NULL
Doctrine gives me VARCHAR, instead of INTEGER as id with foreign key. Does anyone know why?
How to tell Symfony to make a relation in this case?
Don´t use @ORM\Column, just @ORM\ManyToOne: