Yii 2.0 Restful API and MANY_MANY relation

I found the way to handle restful search from this question: <URL>

But I can’t search with MANY_MANY relation condition.

How do I search withe the condition from MANY_MANY relation tables?

My application has these tables:

profile <-> profile_part <-> part

And I request:

GET /profile/search?expand=parts&part_id=4

but I got this error:

<response>

<name>Database Exception</name>

<message>

SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘part_id’ in ‘where clause’ The SQL being executed was: SELECT COUNT(*) FROM profile WHERE (part_id=‘4’)

</message>

Model:




class Profile extends \yii\db\ActiveRecord

{


    public function extraFields()

    {

        return ['parts'];

    }


    public function getParts()

    {

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

                    ->viaTable('{{%profile_part}}', ['profile_id' => 'id']);

    }

}




Controller:




class ProfileController extends ActiveController

{

    public $modelClass = 'app\models\Profile';


    public function actions()

    {

        $actions = parent::actions();


        unset($actions['delete'], $actions['create']);


        $myActions = [

            'search' => [

                'class'       => 'app\components\SearchAction',

                'modelClass'  => $this->modelClass,

                'checkAccess' => [$this, 'checkAccess'],

                'params'      => \Yii::$app->request->get(),

            ],

        ];


        return array_merge($actions, $myActions);

    }


    public function verbs() {

        $verbs = [

            'search'   => ['GET']

        ];

        return array_merge(parent::verbs(), $verbs);

    }

}




Sorry I can’t post the URL…