2011-02-04 14 views
0

中関係は以下の、多くの関係1つを作成しようとしていますと、問題が直面していますのsymfony 1.4 - ドクトリン - モデルスキーマ

Country: 
    actAs: 
     Timestampable: ~ 
     I18n: 
      fields: [country_name] 
    columns: 
     country_code: { type: string(30), notnull:true, unique: true } 
     country_name: { type: string(200), notnull:true } 
     country_flag: { type: string(200), notnull: flase } 
     created_by: {type: bigint, notnull: true } 
     updated_by: {type: bigint, notnull: false } 
    relations: 
     sfGuardUser1: { local: created_by, foreign: id, class: sfGuardUser } 
     sfGuardUser2: { local: updated_by, foreign: id, class: sfGuardUser } 
City: 
    actAs: 
     Timestampable: ~ 
     I18n: 
      fields: [city_name] 
    columns: 
     city_name: { type: string(100), notnull: true } 
     country_code: { type: integer, notnull: true } 
     created_by: {type: bigint, notnull: true } 
     updated_by: {type: bigint, notnull: false }   
    relations: 
     Country: 
      local: country_code 
      foreign: country_code 
      class: Country 
     sfGuardUser1: { local: created_by, foreign: id, class: sfGuardUser } 
     sfGuardUser2: { local: updated_by, foreign: id, class: sfGuardUser } 

が生成されたSQLである私のYMLのsechmaです。上記のymlは両方のテーブルに制約を作成していますが、私はCityテーブルの制約を作成するだけです。どのように私はそれを行うことができます考えですか?

よろしく、id

+2

どのような制約について話していますか? – greg0ire

+0

Countryテーブルのcountry_code列に「unique:true」と表示されていますか? – Tom

+0

この外部キーの制約はありますか?そうであれば、モデル内の関係を手動で管理し、スキーマから取り除くことによってのみそれらを取り除くことができます。 – benlumley

答えて

2

設定foreign、デフォルトの教義でスキーマに手動で設定するまで、主キーがidと呼ばれると考えているため。また、スキーマ(または@benlumneyで述べたモデル)でリレーションタイプを手動で設定します。

relations: 
    Country: 
     local: country_code 
     foreign: id # or you can just skip this param in this case 
     class: Country 
     type: many 
     foreignType: one 
関連する問題