Webonaute / DoctrineFixturesGeneratorBundle

Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.
63 stars 47 forks source link

is ->getId() only one supported primary key identificator (id) ? #19

Closed milan74sk closed 7 years ago

milan74sk commented 8 years ago

or is there any possibility how to specify it by e.g. config, or how to make it work with another PK like id.

My tables have PK record_id not just id. So the bundle should know to call ->getRecordId() and not ->getId(). Before this I can't use it, even it is great utility.

thank you

Webonaute commented 7 years ago

It's fixed in 1.3.0. it now use the primary key identifier.

(not that it is not supporting multiple columns as primary key.)

dlancea commented 7 years ago

I believe this is still an issue, unless I'm doing something else wrong. I'm getting this error on an Entity which has a primary key on a column named "iso"

[Symfony\Component\Debug\Exception\UndefinedMethodException] Attempted to call an undefined method named "getId" of class "AppBundle\Entity\Country".

Edit: I'm also getting this error:

[Doctrine\ORM\ORMException] Entity 'Umem\UtilitiesBundle\Entity\State' has no field 'id'. You can therefore not call 'findById' on the entities' repository

Here's part of the entity definition:

 /**
 * Country
 *
 * @ORM\Table(name="country")
 * @ORM\Entity
 */
class Country {

    /**
     * @var string
     *
     * @ORM\Column(name="iso", type="string", length=2, nullable=false)
     * @ORM\Id
     */
    private $iso;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=80, nullable=false)
     */
    private $name;
Webonaute commented 7 years ago

Are you sure you are on the lastest version 1.3.*?

dlancea commented 7 years ago

I tried with both dev-master and v1.3.2.

The stack trace shows the first error originating from this line: https://github.com/Webonaute/DoctrineFixturesGeneratorBundle/blob/321089ef7fb01ea6151efff0373313a4c7af86a4/Tool/FixtureGenerator.php#L463

The second error from this line: https://github.com/Webonaute/DoctrineFixturesGeneratorBundle/blob/e87e6bc19fa71556a4424b91c2b1df9f3e11347a/Generator/DoctrineFixtureGenerator.php#L101

Webonaute commented 7 years ago

oh yeah true, I forget to remove the old line of code for the id! my bad. going to fix it

Webonaute commented 7 years ago

For your second error, you entity state doesnt have ID. I dont plan to support such entities. its a bad behaviour to not have at least one unique identifier.

Webonaute commented 7 years ago

issue fixed in 1.3.3.

Thank for the head up.