C5-8.4* Doctrine how to save id of associated object by name?

Permalink
I have 2 tables: cars and categories, the cars has an associated category id column:

Cars:
/**
     * Many Cars have One Category
     * @ORM\ManyToOne(targetEntity="CarRental\Car\CarCategory")
     * @ORM\JoinColumn(name="category",referencedColumnName="categoryID",onDelete="SET NULL")
     */
    protected $category;
    private function setCategory($category)
    {
        $this->category = $category;
    }
    public function getCategory()
    {
        return $this->category;
    }
[code]


I have a select box with categories. When the select variable is saved, the category string is passed to the Cars class as date['category'] to save the data.

I just can't figure it out how I can insert the proper category id in the cars' table which corresponds to the category string from the data array.

Will really appreciate your help.

 
hutman replied on at Permalink Reply
hutman
You need to send in the Category object and then it should save the appropriate ID.