1
votes

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

1

1 Answers

1
votes

Minor correction... this will work, however I missed a step in between 2 & 3 that effects the form pages and broke down step 1.

1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.)

2 - Edit ./config/doctrine/schema.yml file. For your view definitions, change the primary:false to primary:true accordingly where you need them. I also noticed that in MySQL since boolean = tinyint(1), the schema.yml detects integer(1) and not boolean. You can also change your integer(1) datatypes to boolean where you need too.

tableName: v_tablename
   columns:
     id:
     type: integer(4)
     fixed: false
     unsigned: false
     primary: false --> change to, primary: true
     default: '0'
     notnull: true
     autoincrement: false

tableName: tablename
   columns:

     active:
     type: integer(1) --> change to, type: boolean
     fixed: false
     unsigned: false
     primary: false
     default: '0'
     notnull: true
     autoincrement: false

3 - php symfony doctrine:build-model

4 - php symfony doctrine:build-forms

5 - php symfony doctrine:generate-module frontend module