Search code examples
symfony-1.4sfdoctrineguard

Attach profile fields to created users in Symfony and sfDoctrineGuard plugin


I'm trying to attach a idempresa field to the sfDoctrineGuardPlugin but can't get it to work. This is the schema.yml (just relevant tables) for those tables:

SdrivingEmpresa:
  connection: doctrine
  tableName: sdriving_empresa
  columns:
    idempresa:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    idlogotipo:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: false
    nombre_empresa:
      type: string(250)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    ruta_emp:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    SdrivingLogotipo:
      local: idlogotipo
      foreign: idlogotipo
      type: one
    SdrivingEmisor:
      local: idempresa
      foreign: idempresa
      type: many
    SdrivingMaquina:
      local: idempresa
      foreign: idempresa
      type: many
    SdrivingOperador:
      local: idempresa
      foreign: idempresa
      type: many
    SdrivingTurno:
      local: idempresa
      foreign: idempresa
      type: many
    SfGuardUserProfile:
      local: idempresa
      foreign: idempresa
      type: many

SfGuardUserProfile:
  connection: doctrine
  tableName: sf_guard_user_profile
  columns:
    user_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    idempresa:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: false
  relations:
    SfGuardUser:
      local: user_id
      foreign: id
      type: one
    SdrivingEmpresa:
      local: idempresa
      foreign: idempresa
      type: one

If I run this:

# php symfony doctrine:dql "FROM sfGuardUser u, u.SfGuardUserProfile p"
>> doctrine  executing dql query

I get this error:

>> DQL: FROM sfGuardUser u, u.SfGuardUserProfile p
>> Unknown relation alias SfGuardUserProfile

What I'm doing wrong? Where is my mistake?


Solution

  • try adding a foreignAlias for sfGuardUser in SfGuardUserProfile entity, like:

     relations:
        SfGuardUser:
          local: user_id
          foreign: id
          type: one
          foreignAlias: SfGuardUserProfile