Vardefs

出典: SugarForum.jp

Vardef は、SugarBeansについての情報 - フィールド、リレーションシップ、インデクスに関する情報 - をSugar アプリケーションへ提供するために使用される。

目次

Vardefsの在処

SugarBeanを提供するモジュールには、定義ファイルである vardefs.php が配置されていて、例として取引先担当者モジュール(Contacts)では、

SugarRoot/modules/Contacts/vardefs.php

に Vardefs がある。一般に、モジュールディレクトリ直下に配置される。

SugarRoot/modules/@モジュール名/vardefs.php

Vardef ファイルは 配列$dictionary を生成し、それには テーブル、フィールド、インデクス、リレーションシップにつてのエントリが含まれている。


Dictionary 配列

  • table : フィールドが定義されているデータベース上のテーブル名(通常はモジュール名)
  • audited : このテーブルで監査機能を使用する場合は、trueに。指定フィールドの変更を記録できる。
  • fields : フィールドのリスト (下記参照)
  • indices : インデクスのリスト (下記参照)
  • relationships : リレーションシップのリスト(下記参照)
  • optimistic_locking : オプティミスティックロックを使用する場合はTrue。 オプティミスティックロックでは、変更日時を参照することにより、作業中のビーンが他から変更されていない事を確認し、データの損失を防いでいる。


Fields 配列

fields 配列では、 SugarBean の各フィールド毎に1つの配列を持つ。

最上位の配列では、フィールド名がキーとなり、属性情報が値として格納されている。

指定可能な属性は下記のとおり。

  • audited : 監査対象にする場合はtrue
  • dbtype : データベース上のデータ型 (typeと異なる場合)
  • db_concat_fields : (for concatinated values only) An array containing the fields to concatenate in the DB.
  • default : 規定値
  • fields : (for concatinated values only) An array containing the fields that are concatenated.
  • id_name : (for type relate only) The field from the bean that stores the id for the related Bean
  • isnull : nullの許容
  • len : フィールド長
  • massupdate : リストビューで「一括アップデート」の項目として表示さたくない場合は false。規定値はtrue
  • name : フィールド名
  • options : 言語ファイルにおける列挙名(=$app_list_strings配列のキー)
  • reportable : レポーティングモジュールでの表示 (可能な場合)
  • required : 必須の場合はtrue
  • rname : (for type relate only) The field from the related variable that has the text
  • source : データベースからデータを取得しない場合は nondb。 計算値や他の方法でデータを取得する場合に使用する。
  • table : このフィールドが定義されているテーブル
  • type : フィールドの型
    • assigned_user_name : 割り当てられたユーザー名
    • bool : ブーリアン
    • char : 文字
    • datetime : 日付/時刻
    • enum : 列挙
    • relate : 関連ビーン
    • varchar : 可変長文字列
  • vname : 言語ファイルにおけるラベル名 (=$mod_stringsのキー)
  • sort_on : 並べ替えを行うフィールド (複数のフィールドが使用されている場合)
  • 'disable_num_format : フィールド型がintにすると、通常「10,000」のようにフォーマットされるが(挿入の位や文字はロケールに依存)、この属性にtrueをセットするとフォーマットしないままにできる。例としては、銀行の口座番号のフィールドや会員番号など


一般的なIDフィールドの例

'id' => array (
  'name' => 'id',
  'vname' => 'LBL_ID',
  'type' => 'id',
  'required'=>true,
),

Indices 配列

この配列にはデータベース上にインデクスを作成する際の情報が入っている。

  • name : インデクス名。データベース上で一意でなければならない。
  • type : インデクスの種類 (プライマリ、ユニーク、インデクス)
  • fields : インデクス化するフィールド。This is an ordered array.

フィールド「id」に対し、「userspk」というプライマリインデクスを作成する場合の例

array('name' =>'userspk', 'type' =>'primary', 'fields'=>array('id')),


Relationships 配列

Bean間のリレーションシップの定義に使用される。インデクス配列と同じように、名前と値の配列で構成される。

  • lhs_module : リレーションシップの親となるモジュール
  • lhs_table : リレーションシップの親となるテーブル
  • lhs_key : 親となるテーブルの主キー
  • rhs_module : リレーションシップの子となるモジュール
  • rhs_table : リレーションシップの子となるテーブル
  • rhs_key : 子となるテーブルの主キー
  • relationship_type : リレーションシップのタイプ (one-to-manymany-to-many)
  • relationship_role_column_value' : ???

contact と person からなる reportingのリレーションシップ の例。 The reports_to_id field is used to map to the id field in the contact of the person they report to. This is a one to many relationship in that each person is only allowed to report to one person. Each person is allowed to have an unlimited number of direct reports.

'contact_direct_reports' => array(
   'lhs_module' => 'Contacts', 
   'lhs_table' => 'contacts', 
   'lhs_key' => 'id',
   'rhs_module' => 'Contacts', 
   'rhs_table' => 'contacts', 
   'rhs_key' => 'reports_to_id',    
   'relationship_type' => 'one-to-many'
),

最終更新 09:05, 2009年9月12日 (土)。   このページは 11,893 回アクセスされました。