简体   繁体   English

myisam和innodb之间的Yii关系-未知的列

[英]Yii relation between myisam and innodb - column unknown

I've two tables, one myisam (boats), one innodb(landing_pages) 我有两个桌子,一个myisam(船),一个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 它们之间的关系在SQL中可以正常工作,但是在yii中,我得到了错误消息bot_models_id未定义,该关系使用了错误的外键

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); 的print_r($ ATMP);

thx! 谢谢!

Yii doesn't perform any foreign key check. Yii不执行任何外键检查。 I suggest you to activate the sql log. 我建议您激活sql日志。 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: 请参阅此链接http://www.yiiframework.com/wiki/58/sql-logging-and-profiling-in-firebug-yii-1-1/在我看来,问题在于:

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. 这意味着yii在表Boats中查找一个名为boat_models_id的字段,并且该字段在表LandingPages中显示为主键。 I think this is not your case. 我认为这不是您的情况。 I think that in your data model a boat as many landing pages and the field boat_models_id belong to the table landinbg_pages. 我认为在您的数据模型中,一艘船与landingbg_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 在这里看看http://www.yiiframework.com/doc/guide/1.1/it/database.arr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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