I have two entities with some properties:
- Category
- category name
- category description
- Subcategory
- subcategory name
- subcategory description
- Category ID (ManyToOne relation)
There is a ManyToOne relation in the subcategory entity i.e. several subcategories can be connected to one category.
I would like to build a form with a dropdown listing all the subcategories, but I would like to display the name of category and subcategory, the list would look like so:
- Category1 - Subcategory1
- Category1 - Subcategory2
- Category1 - Subcategory3
- Category2 - Subcategory1
- Category2 - Subcategory2
- Category2 - Subcategory3
- etc...
I'm thinking about creating a getter in the subcategory class that would return a concatenation of the category name and subcategory name, something like sprintf('%s - %s', $this->categoryName, $this->subcategoryName), but I can't see how I could access Category object properties using the subcategory class getter...
Any idea about the best practice to achieve this?
Thank you, JM