PHP Doctrine - YAML语法帮助。多对多关系的默认值?

时间:2009-11-13 17:40:42

标签: php doctrine yaml relationships

我有以下YAML架构用于在Doctrine中组织用户:

Person:
  tableName: people
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true 
    firstname:
      type: string
      notnull: true
      lastname:
      type: string
      notnull: true
User:
  inheritance:
  extends: Person
    type: column_aggregation
    keyField: type
    keyValue: 1
Userdetails:
  columns:
    person_id:
      type: integer
      primary: true
    password:
      type: string
      notnull: true
  relations:
    User:
      foreignType: one
      local: person_id
      onDelete: CASCADE
      onUpdate: CASCADE
Group:
  tableName: groups
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name:
      type: string
      notnull: true
UserGroup:
  columns:
    group_id:
      type: integer
      primary: true
      person_id:
      type: integer
      primary: true
  relations:
    User:
      foreignType: many
      local: person_id
    Group:
      foreignType: many 

基本上,任何用户都属于一个或多个组 有没有办法在默认情况下将新用户添加到特定组?

任何建议表示赞赏。

由于

1 个答案:

答案 0 :(得分:0)

我必须管理员,我不再使用最新的Doctrine版本,但由于它的记录需要一个默认构造函数,我认为在用户构造函数中从数据库加载默认组就足够了

class User extends Doctrine_Record
{
    public __construct()
    {
        parent::__construct();
        $this->groups[] = Doctrine::getTable('Group')->findByName('DefaultGroup');
    }
}

$blauser = new User();
$blauser->save(); // Will save the user with the default group

根据您的架构,您可能还需要考虑将初始化放入控制器中。