propelorm / PropelBundle

PropelBundle for Symfony.
http://propelorm.org/Propel/documentation/#working-with-symfony2
180 stars 156 forks source link

propel:model:build does not respect database "package" attribute #435

Closed kinekt4 closed 7 years ago

kinekt4 commented 8 years ago

I'm trying to build some models from a schema.xml file and the build process does not respect the package attribute. Although it does respect the namespace attribute.

Schema

<database name="default" defaultIdMethod="native" defaultPhpNamingMethod="underscore"
package="src" namespace="CompanyName\AppBundle\Model">
....
</database>

How to Reproduce

php app/console propel:database:reverse default
cp ./generated-reversed-database/schema.xml ./src/CompanyName/AppBundle/Resource/config/.
php app/console propel:model:build --connection=conn1

The generated models were created here:

CompanyName/AppBundle/Model/
CompanyName/AppBundle/Model/Base
CompanyName/AppBundle/Model/Map

Expected Behaviour

src/CompanyName/AppBundle/Model/
src/CompanyName/AppBundle/Model/Base
src/CompanyName/AppBundle/Model/Map

Work around

rsync -a CompanyName/ src/CompanyName/

Env php: v 5.6 symfony: v 2.8 propel: v2.0 propel bundle: v2.0

marcj commented 8 years ago

If you remove that package attribute, it should be placed in the correct folder.

kinekt4 commented 8 years ago

Hi marcj. Adding or removing the package attribute doesn't seem to make any difference

marcj commented 8 years ago

Are you using the latest propel bundle version? My XML file in my bundles look like

<?xml version="1.0"?>
<database name="default" namespace="Company\CoreBundle\Model">
  <table name="job" allowPkInsert="true">
  </table>
</database>

and is placed in src/Company/CoreBundle/Resources/config/schema/schema.xml. Models will be generated in src/Company/CoreBundle/Model. Works perfectly in all of our projects. I'm using Symfony 2.8 and in newer projects Symfony 3.0, each with PropelBundle of 3.0 branch.

kinekt4 commented 7 years ago

My composer.json

    "symfony/symfony": "2.8.*",
    "propel/propel": "~2.0@dev",
    "propel/propel-bundle": "~2.0@dev",

Should I be using PropelBundle 3.0 instead?

I was following these guidelines:

The 2.0 branch contains Propel2 integration for Symfony 2. The 3.0 branch contains Propel2 integration for Symfony 3.

kinekt4 commented 7 years ago

Issue #436 is related to this issue.

To resolve both issues ensure your database schema follows the following rule:

Schema

<database name="conn1" namespace="CompanyName\AppBundle\Model">

Build

php app/console propel:model:build --connection=conn1

Also, the reverse engineering process adds some attributes to the schema that are no longer required for the build. Keep only the following:

kinekt4 commented 7 years ago

@marcj I think the rule "The name attribute must match the connection you use in your build" is flawed

I may want to (which in this case I do), to reverse engineer from connection default but I want to build for connection conn1 instead.

Specifically - for me:

In a nutshell, I'm doing a work around to reverse-engineer some MS SQL DB tables.

Is it a worthwhile feature request to remove that particular requirement?

kinekt4 commented 7 years ago

As an aside, when I change both places to use the MS SQL connection I get the following error:

[Propel\Generator\Exception\BehaviorNotFoundException]                                                          
Unknown behavior "typehintable". You may try running `composer update` or passing the `--composer-dir` option.

So that's not an option for me atm