sfGuardUser表是否有主键?

时间:2011-05-13 21:09:09

标签: symfony1 doctrine

我是Symfony和Doctrine的新手,正在编写一个Web应用程序。我将sfDoctrineGuardPlugin添加到我的项目中。当我打开插件的schema.yml文件时,我看到了:

sfGuardUser:
actAs: [Timestampable]
columns:
  first_name: string(255)
  last_name: string(255)
  email_address:
    type: string(255)
    notnull: true
    unique: true
  username:
    type: string(128)
    notnull: true
    unique: true
  algorithm:
    type: string(128)
    default: sha1
    notnull: true
  salt: string(128)
  password: string(128)
  is_guest:
    type: boolean
    default: 0
  is_active:
    type: boolean
    default: 1
  is_super_admin:
    type: boolean
    default: false
  last_login:
    type: timestamp
indexes:
  is_active_idx:
    fields: [is_active]
relations:
  Groups:
    class: sfGuardGroup
    local: user_id
    foreign: group_id
    refClass: sfGuardUserGroup
    foreignAlias: Users
  Permissions:
    class: sfGuardPermission
    local: user_id
    foreign: permission_id
    refClass: sfGuardUserPermission
    foreignAlias: Users

此架构是否生成带有主键的表(如果是,我该如何访问它)?我已经在线查看,大多数覆盖sfGuardUser架构的页面都显示了一个作为主键的id列。我错过了什么?感谢。

2 个答案:

答案 0 :(得分:3)

是的,它是id,以sfGuardUser u访问 - > u.id,如......

$user = Doctrine::getTable('sfGuardUser')->findOneById(55);

...或

$q = Doctrine_Query::create()
  ->select('u.*')
  ->from('sfGuardUser u')
  ->where('u.id = ?', 55);
$q->execute();

我认为在Doctrine文档中的某处,如果没有在YAML文件中声明,那么Doc​​trine会自动生成一个“id”主键。它曾经在sfGuardPlugin架构中被声明为explicity,但是从Symfony 1.4.8开始(我认为),它只是没有写。

需要注意的一点是,架构中的其他位置,您需要确保为外键关系的另一端声明相同的数字类型,否则会引发错误。我认为你需要的只是type: integer

答案 1 :(得分:2)

如果没有给出主键,则doctrine将创建一个类型为bigint且带有主键的id字段。

相关问题