困っている点
FuelPHP 1.8.1を使って開発をしています。
FuelPHPのモデルでhas_manyのリレーションを定義したところ以下のようなエラーが表示され困っています。
Fuel\Core\FuelException [ Error ]:
Related model not found by Has_Many relation "events_intarest": Model_EventsIntarest
実装したいこと
eventsに複数のintarestsが紐づくので、中間テーブルのevents_intarestsとeventsテーブルを紐づけたいイメージです。
なので一つのイベントに対し、複数の興味が紐づくイメージです。
例)
イベント: 「山でBBQ!」
興味 : 「アウトドア」, 「BBQ」, 「山」
実装したコード
以下モデルとテーブルの構成です。
php
1//event.php 2<?php 3 4class Model_Event extends \Orm\Model 5{ 6 ・ 7 ・ 8 ・ 9 protected static $_has_many = array( 10 'events_intarest' => array( 11 'key_from' => 'id', 12 'model_to' => 'Model_EventsIntarest', 13 'key_to' => 'event_id', 14 'cascade_save' => false, 15 'cascade_delete' => false, 16 ), 17 ); 18}
php
1//eventsintarest.php 2<?php 3 4class Model_EventsIntarest extends \Orm\Model 5{ 6 ・ 7 ・ 8 ・ 9 protected static $_belongs_to = array( 10 'intarest' => array( 11 'key_from' => 'intarest_id', 12 'model_to' => 'Model_Intarest', 13 'key_to' => 'id', 14 'cascade_save' => false, 15 'cascade_delete' => false, 16 ), 17 'events_intarest' => array( 18 'key_from' => 'event_id', 19 'model_to' => 'Model_Event', 20 'key_to' => 'id', 21 'cascade_save' => false, 22 'cascade_delete' => false, 23 ), 24 ); 25}
events_intarestsテーブル
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
id | int(11) | NO | PRI | NULL | auto_increment |
event_id | int(11) | YES | NULL | ||
intarest_id | int(11) | YES | NULL | ||
#### | |||||
eventsテーブル | |||||
Field | Type | Null | Key | Default | Extra |
:-- | :--: | --: | --: | --: | --: |
id | int(11) | NO | PRI | NULL | auto_increment |
上記のモデル、テーブルの設定だとRelated model not found と怒られてしまいます。
解決方法わかる方いらっしゃいましたらご教授頂けると助かります。
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。