[2.0.3] Bug in HasOne

Hi,

I have a Bug I don’t understand




// Model Ccmd

class Ccmd extends \yii\db\ActiveRecord

{

    public static function tableName()

    {

        return 'ccmd';

    }


    public function rules()

    {

        return [

            [['name'], 'required'],

            [['name'], 'string', 'max' => 255]

        ];

    }


    public function getCmds()

    {

        return $this->hasMany(Cmd::className(), ['id' => 'cmd_id'])

          ->viaTable('cmd_ccmd', ['ccmd_id' => 'id']);

    }


    public function getRules()

    {

        return $this->hasMany(Rule::className(), ['ccmd_id' => 'id']);

    }

}


// Rule cmd

class Rule extends \yii\db\ActiveRecord

{


    public $group = null;


    public static function tableName()

    {

        return 'rule';

    }


    public function getCrouter()

    {

        return $this->hasOne(Crouter::className(), ['id', 'crouter_id']);

    }


    public function getCterm()

    {

        return $this->hasOne(Cterm::className(), ['id', 'cterm_id']);

    }


    public function getCcmd()

    {

        return $this->hasOne(Ccmd::className(), ['id', 'ccmd_id']);

    }


    public function getGroup()

    {


       if ($this->group == null) {

           $this->group = Group::group_search($this->group);

       }

       return $this->group;

    }

}




I try this :




var_dump(Rule::findOne(2)->ccmd);



But I have this error :




SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause'

The SQL being executed was: SELECT * FROM `ccmd` WHERE (`0`, `1`) IN ((2, <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />)



The HasMany relation is working




var_dump(Ccmd::find(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />->rules);



I don’t known if it’s a Yii bug or my code ?

Thanks you

I guess it should look like




public function getCrouter()

    {

        return $this->hasOne(Crouter::className(), ['id' => 'crouter_id']); // and not ['id','crouter_id']

    }


    public function getCterm()

    {

        return $this->hasOne(Cterm::className(), ['id' => 'cterm_id']);

    }


    public function getCcmd()

    {

        return $this->hasOne(Ccmd::className(), ['id' => 'ccmd_id']);

    }