phpsymfonypropelfixturesconcrete-inheritance

Symfony2, Propel fixtures and concrete inheritance


I got an issue with Propel fixtures loading in Symfony2. I have the following schema:

<table name="application" phpName="Application">

   <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
   <column name="name" type="varchar" required="true" primaryString="true" />

   <behavior name="timestampable" />

</table>

<table name="application_iphone" phpName="IphoneApplication">

   <column name="store_id" type="varchar" required="true" />

   <behavior name="concrete_inheritance">
       <parameter name="extends" value="application" />
   </behavior>

</table>

<table name="application_identifier" phpName="IphoneApplicationIdentifier">

    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="application_id" required="true" type="integer" />
    <column name="identifier" type="varchar" required="true" primaryString="true" />

    <foreign-key foreignTable="application_iphone">
        <reference local="application_id" foreign="id" />                                 
    </foreign-key>     

</table>

The model builds correctly. The issue raises when I try to load the following fixtures:

Acme\MyBundle\Model\Application:
    first_app:
        name: "MyFirstApp"
        descendant_class: "IphoneApplication"

Acme\MyBundle\Model\IphoneApplication:
    first_app_iphone:
        id: first_app
        store_id: 2342

Acme\MyBundle\Model\IphoneApplicationIdentifier:     
    first_app_identifier:
        identifier: "com.acme.myfirstapp.appstore"
        application_id: first_app_iphone

The following error occurs:

[Propel] Exception
Cannot insert a value for auto-increment primary key (application.ID)

I added my "first_app" application twice (one in Application, another time in IphoneApplication) to prevent from another issue with my IphoneApplicationIdentifier fixture:

[Propel] Exception The object "first_app" from class "Acme\MyBundle\Model\Application" is not defined in your data file.

How can I insert fixtures for a concrete inheritant model?


Solution

  • Propel is telling you that you are trying to set a value for an autoincrement column, this is due to the

        id: first_app
    

    line.

    If I am understanding you correctly, you just want to add an Iphoneapplication item, is that right? If that is the case you just need to do:

    Acme\MyBundle\Model\IphoneApplication:
        first_app_iphone:
            name: "MyFirstApp"
            store_id: 2342