Progressing through the Symfony 2 documentation I have hit a snag. In most sections where yml, annotations/php or xml can be used the alternatives are provided. In most cases these are interchangeable. However, in regards to Doctrine only one can be used per bundle, I believe. I have choosen to use yml. However, the below information in the docs only shows how to get relational mappings hooked up using annotations which will not work because it one or the other and I am using yml. I would appreciate it if someone could tell mm how to convert the annotations below to doctrine yml.
// src/Acme/StoreBundle/Entity/Category.php
// ...
use Doctrine\\Common\\Collections\\ArrayCollection;
class Category
{
// ...
/**
* @ORM\\OneToMany(targetEntity="Product", mappedBy="category")
*/
protected $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
}
// src/Acme/StoreBundle/Entity/Product.php
// ...
class Product
{
// ...
/**
* @ORM\\ManyToOne(targetEntity="Category", inversedBy="products")
* @ORM\\JoinColumn(name="category_id", referencedColumnName="id")
*/
protected $category;
}
This section is the part this is all outlined in the Symfony 2 docs:
Symfony - Databases and Doctrine (“The Model”)
This is my current yml configuration for the Product and Category entity.
Category.orm.yml
Acme\\StoreBundle\\Entity\\Category:
type: entity
table: category
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: '255'
lifecycleCallbacks: { }
Product.orm.yml
Acme\\StoreBundle\\Entity\\Product:
type: entity
repositoryClass: Acme\\StoreBundle\\Repository\\ProductRepository
table: product
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
price:
type: decimal
scale: 2
description:
type: text
thanks