2009-11-13 2 views
0

Doctrine에서 사용자를 구성하기 위해 다음 YAML 스키마가 있습니다.PHP 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 

기본적으로 사용자 인 모든 사용자는 하나 이상의 그룹에 속하게됩니다.
새로운 사용자를 기본적으로 특정 그룹에 추가 할 수있는 방법이 있습니까?

어떤 조언을 부탁드립니다.

고맙습니다

답변

0

나는 더 이상 가장 최근의 교리 버전 아니지만, 그 기록은 기본 생성자가 필요하기 때문에 나는의 데이터베이스에서 기본 그룹을로드하기에 충분해야한다 생각, 관리자에 있어야합니다 사용자 생성자

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 

아키텍처에 따라 컨트롤러에 초기화를 적용 할 수도 있습니다.

관련 문제