7

I am relatively new to Symfony2 and so far love it - except for this problem that I keep coming up against.

The dreaded (for me): doctrine:generate:entities

When I started my first Symfony2 project I could not get that command working and ended up just using doctrine:generate:entity instead which worked fine.

However, this time I am trying to write an application for a system that already has database tables. I followed the instructions at: Symfony2 Docs which seemed to all work fine except, as usual for the doctrine:generate:entities bit.

I have the following Entity file @ My/Bundle/FeedManagerBundle/Entity/Feeds.php

<?php

namespace My\Bundle\FeedManagerBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Feeds
 *
 * @ORM\Table(name="feeds")
 * @ORM\Entity
 */
class Feeds
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="feed_label", type="string", length=100, nullable=false)
     */
    private $feedLabel;

    /**
     * @var integer
     *
     * @ORM\Column(name="advertiser_id", type="integer", nullable=false)
     */
    private $advertiserId;

    /**
     * @var boolean
     *
     * @ORM\Column(name="active", type="boolean", nullable=false)
     */
    private $active;


}

And in My/Bundle/FeedManagerBundle/Resources/config/doctrine/Feeds.orm.yml

Feeds:
    type: entity
    table: feeds
    fields:
    id:
        id: true
        type: integer
        unsigned: false
        nullable: false
        generator:
            strategy: IDENTITY
    feedLabel:
        type: string
        length: 100
        fixed: false
        nullable: false
        column: feed_label
    advertiserId:
        type: integer
        unsigned: false
        nullable: false
        column: advertiser_id
    active:
        type: boolean
        nullable: false
    lifecycleCallbacks: {  }

And this is the error I am getting:

$ php app/console doctrine:generate:entities My/Bundle/FeedManagerBundle/Entity/Feeds --path=src
Generating entity "My\Bundle\FeedManagerBundle\Entity\Feeds"



  [Doctrine\Common\Persistence\Mapping\MappingException]                                                                         
  Invalid mapping file 'My.Bundle.FeedManagerBundle.Entity.Feeds.orm.yml' for class 'My\Bundle\FeedManagerBundle\Entity\Feeds'.  



doctrine:generate:entities [--path="..."] [--no-backup] name

I have tried changing the name of the yml file to the full path. I have also tried changing the first line of the yml file to the full path and I have tried doing both of those things at the same time. Nothing seems to work & now I am getting to pulling my hair out stage. Can anyone think of any reason why this might not be working?

someuser
  • 2,279
  • 4
  • 28
  • 39

4 Answers4

13

Change Feed.orm.yml to:

My\Bundle\FeedManagerBundle\Entity\Feeds:
   type: entity
   table: feeds
   ...
seferov
  • 4,111
  • 3
  • 37
  • 75
  • Wow - I tried everything but that. I even tried My/Bundle/FeedManagerBundle/Entity/Feeds: THANKS! – someuser Feb 27 '13 at 16:32
  • Same here with my XML file mapping. I had and it was giving the same error. I changed it to and it worked. Thanks! – a4bike Mar 10 '15 at 21:18
1

I had a same issue, but the problem was not there.

In fact, I wanted to change the name of the entity, ie: My\Bundle\FeedManagerBundle\Entity\Aircaft: was going to be My\Bundle\FeedManagerBundle\Entity\Aircraft:

(because the table was "aircaft" :-S)

but I didn't change the file name. when I change aircaft.orm.yml to aircraft.orm.yml (with "r") the command works!!

1

Answer discovered no were after searching for 5 hours...

To Generate entities from yml to model.php, just do this. Focus on the bold text below. The command is:

php app/console doctrine:generate:entities YourAppBundle:ReplaceWithEntityName --path src/

make sure your model.orm.yml file is in your folder

C:\xyz\abc**AppBundle\Resources\config\doctrine** and your yml file has this reference in quotes added in beginning of the mapping code "AppBundle\Entity\Book:"

NadZ
  • 1,024
  • 9
  • 10
0

I solved this issue in different way. orm.yml file of Feeds entity is creating problem, so I deleted it from resource -> config -> doctrine then I ran php app/console doctrine:generate:entities YourBundleName.

This works.

If you want to convert the mapping information into the other supported mapping formats using the doctrine:mapping:convert task. Replace the below namespace with your own. It works 100%.

php app/console doctrine:mapping:convert --namespace="Blogger\BlogBundle\Entity\Blog" yaml src/Blogger/BlogBundle/Resources/config/doctrine
Saugat Bhattarai
  • 2,614
  • 4
  • 24
  • 33