I have 2 Entities: Categories and products. How can I build a relationship between these Entities? Category Entity:
class Category
{
private $id;
private $name;
private $parent;
public function getChildren()
{
return $this->children;
}
//setters and getters
}
Items Entity:
class Items
{
private $id;
private $name;
private $price;
private $color;
private $size;
private $weight;
//getters and setters
}
Category yml:
AppBundle\Entity\Category:
type: entity
oneToMany:
children:
targetEntity: AppBundle\Entity\Category
mappedBy: parent
orderBy:
name: ASC
manyToOne:
parent:
targetEntity: AppBundle\Entity\Category
inversedBy: children
joinColumn:
name: parentId
referencedColumn: id
table: category
repositoryClass: AppBundle\Repository\CategoryRepository
id:
id:
column: id
type: integer
id: true
generator:
generator:
strategy: AUTO
fields:
name:
type: string
lenght: 255
Items yml:
AppBundle\Entity\Items:
type: entity
table: items
repositoryClass: AppBundle\Repository\ItemsRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
price:
type: integer
color:
type: string
length: 255
nullable: true
size:
type: integer
weight:
type: integer
One product can belong to several categories, how can this be done? I think that is the ManyToMany relationship, but I can't build relations correctly. .....................................................................................................................................................................
Add in your Category yml:
Add in your Item yml:
Add in your Item Entity:
Add in your Category Entity: