0

Doctrine でユーザーを整理するための次の YAML スキーマがあります。

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 つまたは複数のグループに属します。
デフォルトで新しいユーザーを特定のグループに追加する方法はありますか?

アドバイスをいただければ幸いです。

ありがとう

4

1 に答える 1

0

Doctrine の最新バージョンではないことを管理する必要がありますが、そのレコードにはデフォルトのコンストラクターが必要なので、users コンストラクターでデータベースからデフォルトのグループをロードするだけで十分だと思います

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

アーキテクチャによっては、その初期化をコントローラーにも入れることを検討したい場合があります。

于 2009-11-13T21:01:17.373 に答える