1

I'm new to Yii here. In the documentation, it seems to imply that gii will create the relations for related models. But when using gii to generate models from DB, it doesn't seem to be the case. For example, I have a user table and a profile table with a column "user_id INTEGER DEFAULT 0", but the relations array is empty in the generated model. Did I do something wrong, or gii just doesn't automatically recognize the relations? Thanks,

4

2 に答える 2

3

参照列のコメントに次のような形式を含めると、Gii は MyISAM テーブルのリレーションを作成します。

CONSTRAINT FOREIGN KEY (name_of_this_field) REFERENCES related_table_name(related_field_name)
于 2013-01-22T21:56:15.017 に答える
1

DB 内の対応するテーブルに外部キーがある場合、Gii は生成されたモデルのリレーションを自動的に作成できますが、すべてのストレージ エンジンが外部キーをサポートしているわけではありません。たとえば、MySQL で MyISAM テーブルを使用する場合、それを定義する方法はありません。

于 2012-02-07T16:48:18.760 に答える