schema.yml using sfDoctrineGuardPlugin

1.2k Views Asked by At

I'm building a schema.yml and I'm trying to add foreign key constraints to the table sf_guard_user.

But, when I do doctrine:insert-sql (edit: doctrine:build --all), the links between my tables and sf_guard_user are not there ! Am I missing something ?

I'm using mysql (InnoDB) and Symfony 1.4

Here's a sample of my schema.yml :

Author:
  connection: doctrine
  tableName: ec_author
  actAs:
    Sluggable:
      fields: [name]
      unique: true
      canUpdate: false
  columns:
    sf_guard_user_id:
      type: integer
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    name:
      type: string(30)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    contents:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
      User:
        class: sfGuardUser
        foreignType: one
        local: sf_guard_user_id
        foreign: id

There are no links to sfGuardUser, even though they are described in schema.yml : alt text alt text

3

There are 3 best solutions below

1
On BEST ANSWER

This one works:

Author:
  connection: doctrine
  tableName: ec_author
  actAs:
    Sluggable:
      fields: [name]
      unique: true
      canUpdate: false
  columns:
    sf_guard_user_id:
      type: integer
      fixed: false
      unsigned: false
      primary: false
      autoincrement: false
    name:
      type: string(30)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    contents:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
      User:
        class: sfGuardUser
        foreignType: one
        local: sf_guard_user_id
        foreign: id
        foreignAlias: author

sf_guard_user_id is a foreign key, then it can't be a primary key. so I changed primary: true to primary: false.

4
On

You should be rebuilding the models and sql as well. Try running:

symfony doctrine:build --all

This will clobber all existing data. If you don't want that, you'll have to write a migration.

2
On

The Class name needs to be the same name as you specified when opening the corresponding table in your schema file.

So, for example, you are using:

relations:
    User:
      class: sfGuardUser
      foreignType: one

The class name here must match the declaration of the sfGuardUser table. Just make sure they are the same. Sometimes, it can be declared as sf_guard_user.

If that is fine, you can try adding a few more definitions to your Relations entry:

relations:
    User:
      class: sfGuardUser
      foreignType: one
      local: sf_guard_user_id
      foreign: sf_guard_user_id