Symfony Database Cookbook

From Littledamien Wiki
Revision as of 00:10, 25 January 2015 by Video8 (talk | contribs) (Created page with "Category:Symfony Category:PHP Category:Web Development == Creating classes with Doctrine == A command line shortcut for the process of creating an entity class d...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Creating classes with Doctrine

A command line shortcut for the process of creating an entity class described in Generating Database Tables and/or Schema:

$ php app/console doctrine:generate:entity --entity="AppBundle:Category" --fields="name:string(100)"

Specifying foreign keys between tables

First create a property within the category/group/type class that will hold the records linked to it.[1]

// src/AppBundle/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();
	}
}

Notes

  1. Relationships/Accosciations, Doctrine documentation, Symfony documentation, "The Book"