2011-08-20 4 views
6

Doctrine 1.2에서 Doctrine_Collection 개체가 해당 테이블로 생성 된 테이블에 대해 Key Mapping을 설정하면 컬렉션의 각 레코드에있는 특정 열의 키가 채워집니다.schema.yml에서 Doctrine_Collection 키 매핑 속성 설정

// test.php 

// ... 
$userTable = Doctrine_Core::getTable('User'); 

$userTable->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'username'); 

이제 사용자 컬렉션 요소 인덱스로 이름 컬럼의 값을 사용합니다 :

당신은 이름 열을 매핑 할 수 있습니다

:

문서의 예는 위의 링크

// test.php 

// ... 
$users = $userTable->findAll(); 

foreach($users as $username => $user) { 
    echo $username . ' - ' . $user->created_at . "\n"; 
} 

sc hema.yml 파일?

답변

5

, 나는 this example 건너 온 :

User: 
    columns: 
    ... 
    attributes: 
    coll_key: username 

우리는 일을 한 후 확인할 수 있습니다 다음 coll_key 속성과 같은 원리를 적용

--- 
User: 
    columns: 
    ... 
    attributes: 
    export: all 
    validate: true 

이 산출 속성이 승인되었음을 확인합니다.

$this->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'username'); 

하나의주의 사항이 있습니다.명시 적으로 slug를 지정해야합니다,

User: 
    actAs: 
    Sluggable: ~ 
    columns: 
    ... 
    attributes: 
    coll_key: slug 
$ symfony doctrine:build --all --no-confirmation 
>> doctrine Dropping "doctrine" database 
>> doctrine Creating "dev" environment "doctrine" database 
>> doctrine generating model classes 
>> file+  /tmp/doctrine_schema_60681.yml 
    ... 
>> doctrine generating form classes 

    Couldn't set collection key attribute. No such field 'slug'.

작동 위를 얻으려면 : 당신은 명시 적으로 사용할 열을 만들 필요가, 또는 다른 교리는 빌드 과정에서 오류가 발생합니다 열에서 Sluggable 템플릿은 일반적으로 자동으로 생성하더라도 : 제안에 대한

User: 
    actAs: 
    Sluggable: ~ 
    columns: 
    ... 
    slug: 
     type: string(50) 
     unique: true 
    attributes: 
    coll_key: slug 
0

가능한 경우 잘 설명되어 있지 않습니다. 다음

User: 
    options: 
    attr_coll_key: username 

User: 
    options: 
    attrCollKey: username 

또는

User: 
    options: 
    108: username 
: 당신은 like this

const ATTR_COLL_KEY    = 108; 

내가 시도 할 것이라는 점을 알고, 테이블 정의의 테이블에 대한 옵션을 지정할 수 있습니다 0

코드에서 옵션이 처리되는 위치를 정확하게 찾을 수 없지만 xdebug 단계별 디버깅을 통해이 작업을 수행 할 수 있습니다.

행운을 빈다. 이러한 시도 중 하나가 작동하면 사용을 알리십시오. 비슷한 문제를 탐험하는 동안

+0

감사합니다; 그들은 훌륭한 출발점이었습니다! 나는 그것을 옵션이 아닌 속성으로 지정함으로써 작동시킬 수있었습니다 (자세한 내용은 내 대답 참조). –

+0

@Phoenix : 당신이 스키마에서 속성을 설정할 수 있다는 것을 알지 못 했습니 다. – greg0ire