I have an Item entity and a Category entity. An Item has one Category. My mapping code looks like this:
// Item.php
/**
* @ORM\ManyToOne(targetEntity = "Category")
* @ORM\JoinColumn(name = "category_id", referencedColumnName = "id")
*/
protected $category;
To create the association, I use this method:
// Item.php
public function setCategory(Category $category) {
$this->category = $category;
}
This works fine as long as I first fetch the Category entity from the DB. But I’m wondering if it’s possible to pass an id instead of the Category entity. I’d like to manually set the JoinColumn category_id with a scalar value. But sine category_id isn’t an actual member of Item, I’m not sure how I can do this.
Use
getReference: