2011-09-12 7 views
0

私はsymfony 1.4 & doctrineを使ってプロジェクトを進めています。私のschema.ymlの1.2symfony/doctrine従業員のgetOrganisation()は文字列を返します(ただしオブジェクトが必要です)

私は、従業員と組織エンティティ定義された:私は、コマンドsymfony doctrine:build --all --and-loadを実行し

employee: 
    tableName: employee 
    columns: 
    id: 
     primary: true 
     type: integer(8) 
     notnull: true 
     autoincrement: true 
    organization: 
     default: NULL 
     type: integer 
    relations: 
    organization: 
     onDelete: restrict 
     local: organization 
     foreign: id 
organization: 
    tableName: organization 
    columns: 
    id: 
     primary: true 
     unique: true 
     type: integer 
     notnull: true 
     autoincrement: true 
    relations: 
    employee: 
     type: many 
     class: employee 
     local: id 
     foreign: organization 

を、これは(再)に応じて、テーブルとのphp-クラスでデータベースを作成しますschema.yml。

今私が$employee->getOrganization()($従業員が従業員であると仮定して)を実行すると、クラス構成のオブジェクトを取得することが期待されます。しかし、私は組織のIDフィールドの内容で文字列を取得します。 私はそれ以外の方法でそれを試してみます:$organization->getEmployee()($ organizationはクラス組織であると仮定します)、すべての従業員と共にDoctrine_Collectionを返します。

組織オブジェクトを返すにはどのようにしてgetOrganization()を返すのですか?

答えて

2

ローカルフィールドとリレーションの両方が同じ名前(「組織」)を持っているため、機能しません。

employee: 
    tableName: employee 
    columns: 
    id: 
     primary: true 
     type: integer(8) 
     notnull: true 
     autoincrement: true 
    organisation_id: # renamed to 'organisation_id' 
     default: NULL 
     type: integer 
    relations: 
    Organisation:  # capitalized 
     onDelete: restrict 
     local: organisation_id #renamed to 'organisation_id' 
     foreign: id 

は今、あなたは$employee->organisation_id$employee->getOrganisationId()を使用してIDを取得することができ、かつ$emplyee->Organisationまたは$employee->getOrganisation()のような組織:

これは、教義の命名のガイドライン」を従う方が良いでしょう。

+0

Gradの「組織」を「組織」(北米以外の国での綴り)として再表示しても、それは間違いではありません。 –

+0

@コリンファイン:ハハ、オクラホマ、私はNAの外にいて、Zを好む。 : – Mathias

+0

@コリンoops ...申し訳ありません... ;-) zが許可されていることを知りませんでした... –

関連する問題