With symfony 1.4 and doctrine you can generate frontend pages / modules with this command in your project directory: php symfony doctrine:generate-module --with-show --non-verbose-templates frontend tablename tableclassname
This works great with actual tables, however when I try to run this command on top of a MySQL DB View instead of a MySQL DB Table, I get this error: Cannot generate a module for a model without a primary key. The view inherits the primary key from the table it's reading off of, is my understanding.
Does anyone know a work around for this, that is still pretty easy to maintain with symfony? It would be amazing if I could use DB Views with the symfony framework. Let me know if you need any more details. In general no view seems to work no matter how complex or simple.
P.S. I tried editing the ./config/doctrine/schema.yml file to change the id column in the view to the primary key, which it is in the actual table & I still get the same error when trying to generate the frontend module in symfony.
tableName: v_tablename
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true --> This used to be primary: false
default: '0'
notnull: true
autoincrement: false
*K I figured it out, but I can't post my answer until after 8 hours since I am a new user. I was 1/2 way there when I edited the schema.yml file. If you are trying to generate a module off a view, and you have built your DB Model outside of symfony, say using MySQL Workbench, with doctrine you have to build your schema then build your model in symfony from your existing Database Structure like this:
1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.) However if you have views in your Database Schema, the primary keys aren't generated in the schema.yml file. Edit it manually and change the primary:false to primary:true accordingly where you need them.
2 - php symfony doctrine:build-model Once you do step 2 after adding your primary keys, you can then successfully generate your module
3 - php symfony doctrine:generate-module frontend module model