propelorm / Propel

Current stable (and outdated and unmaintained) version of Propel - Please use v2 https://github.com/propelorm/Propel2 --
http://www.propelorm.org
MIT License
841 stars 417 forks source link

Can not generate files when having a table without a primaryKey column #916

Open stevleibelt opened 10 years ago

stevleibelt commented 10 years ago

Using following schema.xml

<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<database name="test" defaultIdMethod="native" namespace="Application\Model\Database\Test">

    <table name="test" phpName="Test" idMethod="native">
        <column name="example" type="CHAR" size="32" required="true" defaultValue=""/>

        <vendor type="mysql">
            <parameter name="Engine" value="InnoDB"/>
        </vendor>
    </table>
</database>

I get some kind of the following error when executing the generation.

    [exec] [propel-om] Loading XML schema files...
     [exec] [propel-om] 1 tables found in 1 schema files.
     [exec] [propel-om] Generating PHP files...
     [exec] [propel-om]         -> Creating Application/Model/Database/Test/om/BaseTestPeer.php (table: test, builder: PHP5PeerBuilder)
     [exec] [propel-om]         -> Creating Application/Model/Database/Test/om/BaseTest.php (table: test, builder: PHP5ObjectNoCollectionBuilder)
     [exec] [propel-om]         -> Creating Application/Model/Database/Test/map/TestTableMap.php (table: test, builder: PHP5TableMapBuilder)
     [exec] PHP Fatal error:  *Call to a member function getPhpName() on a non-object in* /srv/www/trunk/vendor/propel/propel1/generator/lib/builder/om/QueryBuilder.php on line 478
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /srv/www/trunk/vendor/propel/propel1/generator/bin/phing.php:0
     [exec] PHP   2. Phing::fire() /srv/www/trunk/vendor/propel/propel1/generator/bin/phing.php:54
     [exec] PHP   3. Phing::start() /srv/www/trunk/vendor/phing/phing/classes/phing/Phing.php:278
     [exec] PHP   4. Phing->runBuild() /srv/www/trunk/vendor/phing/phing/classes/phing/Phing.php:170
     [exec] PHP   5. Project->executeTargets() /srv/www/trunk/vendor/phing/phing/classes/phing/Phing.php:590
     [exec] PHP   6. Project->executeTarget() /srv/www/trunk/vendor/phing/phing/classes/phing/Project.php:797
     [exec] PHP   7. Target->performTasks() /srv/www/trunk/vendor/phing/phing/classes/phing/Project.php:824
     [exec] PHP   8. Target->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:320
     [exec] PHP   9. Task->perform() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:297
     [exec] PHP  10. UnknownElement->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Task.php:260
     [exec] PHP  11. PhingTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/UnknownElement.php:96
     [exec] PHP  12. PhingTask->processFile() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:150
     [exec] PHP  13. Project->executeTarget() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:277
     [exec] PHP  14. Target->performTasks() /srv/www/trunk/vendor/phing/phing/classes/phing/Project.php:824
     [exec] PHP  15. Target->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:320
     [exec] PHP  16. Task->perform() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:297
     [exec] PHP  17. UnknownElement->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Task.php:260
     [exec] PHP  18. PhingCallTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/UnknownElement.php:96
     [exec] PHP  19. PhingTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingCallTask.php:158
     [exec] PHP  20. PhingTask->processFile() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:150
     [exec] PHP  21. Project->executeTarget() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:277
     [exec] PHP  22. Target->performTasks() /srv/www/trunk/vendor/phing/phing/classes/phing/Project.php:824
     [exec] PHP  23. Target->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:320
     [exec] PHP  24. Task->perform() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:297
     [exec] PHP  25. UnknownElement->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Task.php:260
     [exec] PHP  26. PhingCallTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/UnknownElement.php:96
     [exec] PHP  27. PhingTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingCallTask.php:158
     [exec] PHP  28. PhingTask->processFile() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:150
     [exec] PHP  29. Project->executeTarget() /srv/www/trunk/vendor/phing/phing/classes/phing/tasks/system/PhingTask.php:277
     [exec] PHP  30. Target->performTasks() /srv/www/trunk/vendor/phing/phing/classes/phing/Project.php:824
     [exec] PHP  31. Target->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:320
     [exec] PHP  32. Task->perform() /srv/www/trunk/vendor/phing/phing/classes/phing/Target.php:297
     [exec] PHP  33. UnknownElement->main() /srv/www/trunk/vendor/phing/phing/classes/phing/Task.php:260
     [exec] PHP  34. PropelOMTask->main() /srv/www/trunk/vendor/phing/phing/classes/phing/UnknownElement.php:96
     [exec] PHP  35. PropelOMTask->build() /srv/www/trunk/vendor/propel/propel1/generator/lib/task/PropelOMTask.php:152
     [exec] PHP  36. OMBuilder->build() /srv/www/trunk/vendor/propel/propel1/generator/lib/task/PropelOMTask.php:92
     [exec] PHP  37. QueryBuilder->addClassBody() /srv/www/trunk/vendor/propel/propel1/generator/lib/builder/om/OMBuilder.php:54
     [exec] PHP  38. QueryBuilder->addFindOneByPk() /srv/www/trunk/vendor/propel/propel1/generator/lib/builder/om/QueryBuilder.php:197
     [exec] Result: 255

Adding a primary key to the column in the schema end everything is working as expected.

<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<database name="test" defaultIdMethod="native" namespace="Application\Model\Database\Test">

    <table name="test" phpName="Test" idMethod="native">
        <column name="example" type="CHAR" size="32" primaryKey="true" required="true" defaultValue=""/>

        <vendor type="mysql">
            <parameter name="Engine" value="InnoDB"/>
        </vendor>
    </table>
</database>

Bad thing about the fact, all I can and must do is using the database. But I can not simple add a primary key to the table. Any ideas?

fliespl commented 10 years ago

Do you need model for that one? You can simply exclude this table from generator.

Also - what is the problem with adding primary key? Your queries (in 99%) won't break if you do so.

stevleibelt commented 10 years ago

Hey @fliespl

yes, the models are needed/at least would be nice to have.

Yes, you can add the primary key but as you mention, this is not bullet proof. I would not go this way because I don't want to be the one who has the joy to debug this one percent.