views:

126

answers:

4

Hello,

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

+1  A: 

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.

jeremy
+1 insert-sql just inserts the schema.sql file. If you do not regenerate it, it won't work.
greg0ire
Even with build --all the links aren't there. Am I supposed to change the schema.yml inside the plugin ?
Manu
When you say the links aren't there, where are they missing? Is it missing in SQL (i.e. no FK from sf_guard_user_id to sf_guard_user table)? Does BaseAuthor add a relation from sf_guard_user_id to User?
jeremy
In sql yes. Also, I can't create a fixture for sfguarduser with data from the profile table (Authors)
Manu
A: 

I tried modifying the plugin's schema.yml, but even that doesn't work :(

  relations:
    Profile:
      class: Authors
      local: user_id
      foreign: sf_guard_user_id
      foreignAlias: Users
Manu
+1  A: 

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
Jon
Thanks for your answer, I've added your suggestions but the link still isn't there :(
Manu
Are you able to populate the tables? Does it cause a FK error when you try to add a FK that does not exist?
Jon
+1  A: 

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.

Peter Long
By the way, there will be a primary key named id in your table ec_author. It is generated automatically(if you didn't declare a primary key explicitly).
Peter Long
It works ! Finally ! I love you :)
Manu