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:
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.
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]
Viewing 15 lines of 47 lines. View entire code block.
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.