Generate Symfony2 fixtures from DB?

There’s no direct manner within Doctrine or Symfony2, but writing a code generator for it (either within or outside of sf2) would be trivial. Just pull each property and generate a line of code to set each property, then put it in your fixture loading method. Example: <?php $i = 0; $entities = $em->getRepository(‘MyApp:Entity’)->findAll(); foreach($entities … Read more

Doctrine2 one-to-one relation auto loads on query

Here is solutions explain with details : https://groups.google.com/forum/#!topic/doctrine-user/fkIaKxifDqc “fetch” in the mapping is a hint, that is, if it is possible Doctrine does that, but if its not possible, obviously it does not. Proxying for lazy-loading is simply not always possible, technically. The situations where its not possible are: 1) one-to-one from inverse to owning … Read more

Doctrine Cascade Options for OneToMany

In the Doctrine2 documentation “9.6. Transitive persistence / Cascade Operations” there are few examples of how you should configure your entities so that when you persist $article, the $topic would be also persisted. In your case I’d suggest this annotation for Topic entity: /** * @OneToMany(targetEntity=”Article”, mappedBy=”topic”, cascade={“persist”, “remove”}) */ private $articles; The drawback of … Read more

Doctrine2 – No Metadata Classes to process

I think you took the config example from Doctrine2: getting started: $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration([__DIR__.”/src”], $isDevMode); The trick is now that the Setup::createAnnotationMetadataConfiguration method uses a SimpleAnnotationReader by default. You can change this behaviour by changing the fifth parameter to false: $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration([__DIR__.”/src”], $isDevMode, null, null, false); This will … Read more

Zend Framework 2 Doctrine 2 one-to-many checkbox hydration

class RoleForm extends Form implements InputFilterProviderInterface { public function __construct(ObjectManager $objectManager) { // … $this->add(array( ‘name’ => ‘rolePermissions’, ‘type’ => ‘Zend\Form\Element\Collection’, ‘options’ => array( ‘label’ => ‘Role Permissions’, ‘count’ => 0, ‘should_create_template’ => true, ‘allow_add’ => true, ‘target_element’ => array( ‘type’ => ‘Zend\Form\Fieldset’, ‘options’ => array( ‘use_as_base_fieldset’ => true ), ‘elements’ => array( // add … Read more

Auto quote reserved words with Doctrine 2

This was an issue I raised a while back with the Doctrine team. https://github.com/doctrine/doctrine2/issues/2409 The ticket was closed with the comment: You have to manually escape characters with @Column(name=”`integer`”) So I guess you’d need to deal with any reserved keywords in your annotations

tech