Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could we get propel build to run dump-autoload? #835

Closed
kitsunde opened this issue Dec 8, 2014 · 8 comments
Closed

Could we get propel build to run dump-autoload? #835

kitsunde opened this issue Dec 8, 2014 · 8 comments

Comments

@kitsunde
Copy link
Contributor

kitsunde commented Dec 8, 2014

After running build for the first time my new model wasn't loading properly which after an hour+ of digging around was because I needed to run composer dump-autoload. This is mentioned in the docs http://propelorm.org/documentation/02-buildtime.html

When I mentioned it on gitter.im @staabm suggested making an issue to have propel run dump-autoload by itself.

The conversation on gitter.im went like this:

I added a m2m relation between Company and Language, it seem to have generated all the related files but now I'm getting:

<br />
<b>Fatal error</b>:  Uncaught exception 'Propel\Runtime\Map\Exception\TableNotFoundException' with message 'Cannot fetch TableMap for undefined table phpName: \Model\CompanyLanguage.' in /var/www/vendor/propel/propel/src/Propel/Runtime/Map/DatabaseMap.php:209
Stack trace:
#0 /var/www/vendor/propel/propel/src/Propel/Runtime/Map/TableMap.php(636): Propel\Runtime\Map\DatabaseMap-&gt;getTableByPhpName('\Model\CompanyL...')
#1 /var/www/application/propel/generated-classes/Model/Map/CmsCompanyTableMap.php(298): Propel\Runtime\Map\TableMap-&gt;addRelation('CompanyLanguage', '\Model\CompanyL...', 2, Array, NULL, NULL, 'CompanyLanguage...')
#2 /var/www/vendor/propel/propel/src/Propel/Runtime/Map/TableMap.php(690): Model\Map\CmsCompanyTableMap-&gt;buildRelations()
#3 /var/www/vendor/propel/propel/src/Propel/Runtime/Map/TableMap.php(674): Propel\Runtime\Map\TableMap-&gt;getRelations()
#4 /var/www/application/propel/generated-classes/Model/Base/CmsCompanyQuery.php(2372): Propel\Runtime\Map\TableMap-&gt;getRelation('CmsCompanyI18n')
#5 /var/www/application/ in <b>/var/www/vendor/propel/propel/src/Propel/Runtime/Map/DatabaseMap.php</b> on line <b>209</b><br />

When I looked in the model directory CompanyLanguage.php is definitely there. Which then turned out I had to run composer dump-autoload.

@marcj
Copy link
Member

marcj commented Dec 8, 2014

Why do you have to run dump-autoload? You only have to call this command when you want the optimized autoload files from composer. I'm OK with a hint message at the end, but I don't see the need to fire composer dump-autoload now directly through our commands.

@kitsunde
Copy link
Contributor Author

kitsunde commented Dec 8, 2014

@marcj I had to run it because Propel wasn't picking up my intermediary model \Model\CompanyLanguage. until I ran dump-autoload.

@marcj
Copy link
Member

marcj commented Dec 8, 2014

Have you added the namespace to your composer.json? It should then be found automatically.

@kitsunde
Copy link
Contributor Author

kitsunde commented Dec 8, 2014

@marcj Yes, my composer.json look like this:

{
    "name": "patontheback",
    "minimum-stability": "dev",
    "require": {
        "igorw/get-in": "~1.0",
        "raven/raven": "dev-master",
        "propel/propel": "~2.0@dev",
        "monolog/monolog": "1.11.0"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.*",
        "mustangostang/spyc": "0.5.*"
    },
    "autoload": {
        "classmap": ["application/propel/generated-classes/"]
    }
}

So what I did was that I added:

  <table name="language">
    <column name="id" autoIncrement="true" type="integer" primaryKey="true"/>
    <column name="code" required="true" type="VARCHAR" size="4"/>
    <column name="name" required="true" type="VARCHAR" size="20"/>
    <unique>
      <unique-column name="code" />
    </unique>
  </table>

  <table name="company_language" isCrossRef="true">
    <column name="company_id" type="integer" primaryKey="true"/>
    <column name="language_id" type="integer" primaryKey="true"/>
    <foreign-key foreignTable="cms_company">
      <reference local="company_id" foreign="com_id"/>
    </foreign-key>
    <foreign-key foreignTable="language">
      <reference local="language_id" foreign="id"/>
    </foreign-key>
  </table>

Then ran propel diff, propel migrate, propel build. The Language model seemed to load fine, but the CompanyLanguage model did not. I suppose if it should've had CompanyLanguage available already then I must have hit some issue that was preventing it from being loaded until dump-autoload making my issue somewhat mislabeled.

@marcj
Copy link
Member

marcj commented Dec 8, 2014

You should not use classmap but psr-0 or psr-4 instead, so you have only to call composer dump-autoload once - if at all, since composer update calls this command already at the end.

    "autoload": {
        "psr-4": {
            "Model\\": "application/propel/generated-classes/"
        }
    },

@kitsunde
Copy link
Contributor Author

kitsunde commented Dec 8, 2014

@marcj Oh okay, I will do that and consider the issue closed. The docs http://propelorm.org/documentation/02-buildtime.html says:

{
  ...
  "autoload": {
    "classmap": ["generated-classes/"]
  }
}

@staabm
Copy link
Member

staabm commented Dec 8, 2014

@marcj dump-autoload is used to (re)generate the classmaps. For the optimzed classmaps you need a additional arg. Just to let you know.

@marcj
Copy link
Member

marcj commented Dec 8, 2014

Thanks, I knew that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants