one2many

I have two tables

Quote - has ID column

Quote detail has - Quote_id column

I have models for them both that work perfectly.

I have a view that should combine the two tables

at the moment I have done this in my controller. (profileController)




    public function actionView($id)

    {

        $searchModel = new QuoteSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        $searchDetailModel = new QuoteDetailSearch();

        $dataDetailProvider = $searchDetailModel->search(Yii::$app->request->queryParams);




        return $this->render('view', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

            'searchDetailModel' => $searchDetailModel,

            'dataDetailProvider' => $dataDetailProvider,

            'model' => $this->findModel($id),

            'modelDetail' => $this->findModel($id),


       // return $this->render('view', [

       //     'model' => $this->findModel($id),

        ]);

    }



what I need to do is filter the quotedetail table by the quote ID and then loop through the fields adding them to the view.

What do I need to do…

So after some more research…

in my View file


<?php

            $QuoteDetail = QuoteDetail::find()

                -> where(['quote_id',$model->id])

                ->all();


            foreach($QuoteDetail as $QuoteDetail) {

                echo "details = {$QuoteDetail->part_description}\n";

            }

            ?>

in my quote model


/**

     * @return \yii\db\ActiveQuery

     */

    public function getQuoteDetails()

    {

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

    }

in my quote detail model


   /**

     * @return \yii\db\ActiveQuery

     */

    public function getQuote()

    {

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

    }

but i get an error class not found

cheers

Where?

Thanks for your response but i did solve it in the end :)

thank you