Last active
July 23, 2016 17:22
-
-
Save arth2o/72a2baae0a099db9cab3 to your computer and use it in GitHub Desktop.
Doctrine Cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Doctrine generate entity/entities from database:table | |
php app/console doctrine:mapping:import --force GleamPageBundle xml | |
php app/console doctrine:mapping:convert annotation ./src | |
php app/console doctrine:generate:entities GleamPageBundle | |
Creating the Database Tables/Schema | |
php app/console doctrine:schema:update --force | |
------------------------ | |
Save Elements: | |
$product = new Product(); | |
$product->setName('A Foo Bar'); | |
$product->setPrice('19.99'); | |
$product->setDescription('Lorem ipsum dolor'); | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($product); | |
$em->flush(); | |
------------------------ | |
GetRepository: | |
$repository = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product'); | |
------------------------ | |
Find: | |
$product = $repository->find($id); | |
// dynamic method names to find based on a column value | |
$product = $repository->findOneById($id); | |
$product = $repository->findOneByName('foo'); | |
// find *all* products | |
$products = $repository->findAll(); | |
// find a group of products based on an arbitrary column value | |
$products = $repository->findByPrice(19.99); | |
------------------------ | |
Debug Ductrine | |
exit(\Doctrine\Common\Util\Debug::dump($yourDoctrineResult)); | |
------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @arth2o 👍