それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

symfonyにテーブルを作らせた方が嬉しい

symfonyにテーブルを作らせた方が楽に思えてきた。
schema.ymlにカラムの定義を書くのだけれど。書き方わからん

symfony prople-build-schema

で試しにスキーマファイルをつくる。

あとは、それを真似ると良い。

ただ、特殊な書き方があるらしい。

カラム名を書いて定義を空にするとsymfonyが自動処理

Empty Columns //空のカラム定義のこと

When meeting a column with no value, symfony will do some magic and add a value of its own. See Listing 8-31 for the details added to empty columns.

//カラム定義を、空っぽにしておくと、symfonyは特殊な値を自動的に追加してくれる。特殊カラム定義のパターンは以下の通り。

Listing 8-31 - Column Details Deduced from the Column Name

// Empty columns named id are considered primary keys
// "id: " と書かれた、空カラム定義はPK定義に書き換わる
id:         { type: integer, required: true, primaryKey: true, autoIncrement: true }

// Empty columns named XXX_id are considered foreign keys
// "XXX_id: " と書かれた空カラム定義は foregin key になる。
//    XXXテーブルの id を参照する外部キー
foobar_id:  { type: integer, foreignTable: db_foobar, foreignReference: id }

// Empty columns named created_at, updated at, created_on and updated_on
// are considered dates and automatically take the timestamp type

// created_at と update_on と書かれた定義は timestamp型になる
// また更新時にsymfonyが自動で値を挿入する
created_at: { type: timestamp }
updated_at: { type: timestamp }

For foreign keys, symfony will look for a table having the same phpName as the beginning of the column name, and if one is found, it will take this table name as the foreignTable.
// foreign keysを定義するときに、symfonyはphpNameを見てそれの定義からカラム名を類推し、外部テーブルとして採用する。(この訳いい加減 たぶん XXX_userid とかけば XXXテーブルの userid を、 XXX_idと書けば、XXXテーブルのid 参照するって事だろう。。)

追記

マニュアルをもう少し読み込んでみた。
phpName は カラム定義で

_attributes: {phpName : XXXX }

と書いた名前のこと。

だから、

ABC_key :

と書けば

Sample_TABLE:
  _attributes: {phpName : ABC }
  key : longvarchar

を参照しに行くってことらしい。

カラム定義に書けるモノ

マニュアルには、こう書いてあった。

If you define only one attribute, it is the column type. Symfony understands the usual column types: boolean, integer, float, date, varchar(size), longvarchar (converted, for instance, to text in MySQL), and so on. For text content over 256 characters, you need to use the longvarchar type, which has no size (but cannot exceed 65KB in MySQL). Note that the date and timestamp types have the usual limitations of Unix dates and cannot be set to a date prior to 1970-01-01. As you may need to set older dates (for instance, for dates of birth), a format of dates "before Unix" can be used with bu_date and bu_timestamp.

//ざっくり訳
属性を書けば、symfonyがDBカラムタイプから適当なモノを探して定義する。使える汎用名は boolean, integer, float, date, varchar(SIZE), longvarchar(MySQLのときはTEXT型を意味する )など。ASCIIで256文字以上ならサイズ制限のないlongvarcharを選択する必要がある。(MYSQLだと65KB制限があるが)。DATEとTIMESTAMPはOSで使ってるUNIXの制限を受ける。つまり1970-01-01より以前は指定できないって事。そういうときは"before Unix" を意味する修飾語bu_をつけて "bu_date", "bu_timespamp"とか書けばいい

読んだときに軽く訳したヤツをメモ代わりに貼っておく。