Skip to content
Advertisement

How to make propel build models with namespaces in the right directory?

Default directory for my classes is: app/

Composer autoload config is:

{
    "autoload": {
        "psr-4": { "App\": "app/" }
    }
}

On propel’s schema.xml my namespace is "AppModels"

<database name="default" defaultIdMethod="native"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
          namespace="AppModels"
        >
    <table name="user">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="email" type="varchar" size="255" required="true"/>
        <column name="password" type="varchar" size="60" required="true"/>
        <column name="country_id" type="integer" required="true"/>
        <column name="timezone" type="varchar" size="50" required="true"/>
        <foreign-key foreignTable="country">
            <reference local="country_id" foreign="id"/>
        </foreign-key>
    </table>

    <table name="country">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="name" type="varchar" size="128" required="true"/>
    </table>
</database>

My propel.php.dist is:

<?php
return [
    'propel' => [
        'paths' => [
            // The directory where Propel expects to find your `schema.xml` file.
            'schemaDir' => 'database/schemas',

            // The directory where Propel should output generated object model classes.
            'phpDir' => 'app/Models'
        ]
    ]
];

When I execute vendor/bin/propel model:build the resulting structure is like this:

/app/
|___Models/
    |___App/
        |___Models/
            |___Base/
            |___Map/
            |___Country.php
            |___CountryQuery.php
            |___User.php
            |___UserQuery.php

I need the structure to be like this:

/app/
|___Models/
    |___Base/
    |___Map/
    |___Country.php
    |___CountryQuery.php
    |___User.php
    |___UserQuery.php

I tried every combination in this manual: Database Attributes

Is there a different way to approach this?

Thanks in advance.

Advertisement

Answer

The configuration specified in the question looks correct, except for one thing that is missing, which made it work in my case: set namespaceAutoPackage to false. In the case of the question’s php configuration file, that looks like this:

<?php
return [
    'propel' => [
        'paths' => [
            // The directory where Propel expects to find your `schema.xml` file.
            'schemaDir' => 'database/schemas',

            // The directory where Propel should output generated object model classes.
            'phpDir' => 'app/Models'
        ],
        'generator' => [
            'namespaceAutoPackage' => 'false'
        ]
    ]
];
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement