简体   繁体   中英

Yii relation between myisam and innodb - column unknown

I've two tables, one myisam (boats), one innodb(landing_pages)

The relation between them works in SQL fine, but in yii I got the error-message bot_models_id is not defined, the relation used a wrong foreign key

How can I deactivate this check, or do you know to to do it?

My relation

public function relations()
{
    return array(
        'landingPages'  => array(self::BELONGS_TO, 'LandingPages', 'boat_models_id',
        ),
    );
}

Try to get the data

$oCriteria = new CDbCriteria();
$oCriteria->with = array(
    'landingPages'  => array('select' => 'url'),
);
$aBoats = Boats::model()->findAll($oCriteria);

print_r($aTmp);

thx!

Yii doesn't perform any foreign key check. I suggest you to activate the sql log. You will immediatly find a wrong query. See this link http://www.yiiframework.com/wiki/58/sql-logging-and-profiling-in-firebug-yii-1-1/ In my opinion the problem is the following:

public function relations()
{
  return array( 
      'landingPages'  => array(self::BELONGS_TO, 'LandingPages', 'boat_models_id',
      ),
  );
}

This mean that yii look for a field called boat_models_id in the table boats and this field appear as primary key in the table landingPages. I think this is not your case. I think that in your data model a boat landing pages and the field boat_models_id belong to the table landinbg_pages. 着陆页和boat_models_id字段都属于表。 The right way to say this is:

public function relations()
{
    return array(
        'landingPages'  => array(self::HAS_MANY, 'LandingPages', 'boat_models_id',
        ),
    );
}

Take a look here http://www.yiiframework.com/doc/guide/1.1/it/database.arr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM