Get Name Of Product In Many Many Relation

Hi, how can i get the name of product in many many relation.

ex:

produto model


            'tabuleiro' => array(self::MANY_MANY, 'tabuleiro', 'tabuleiro_produto(id_produto,id_tabuleiro)'),



tabuleiro model


            'produto' => array(self::MANY_MANY, 'produto', 'tabuleiro_produto(id_produto,id_tabuleiro)'),



then i try to use ĩn cgridview


'tabuleiro_id' => array(

            'name' => 'tabuleiro_id',

            'type' => 'raw',

            'value' => '$data->tabuleiro->descricao',

            'value' => 'Chtml::link(Chtml::encode($data["tabuleiro_id"]),array("tabuleiro/view","id"=>$data["tabuleiro_id"]))',

            'filter' => CHtml::listData(Tabuleiro::model()->findAll(array('order' => 'descricao')), 'id', 'descricao')

        ),

but cant get the descricao field from Tabuleiro model.

If it’s a many-many relationship then the tabuleiro relation will return an array of models. Do you want to display the descriptions of all of them or just the first?

Just the first.

but by the way , how can i display all.

thanks keith

Something like this:




'value' => 'isset($data->tabuleiro[0]) ? $data->tabuleiro[0]->descricao : ""',



To show all, you’d either iterate through each element in $data->tabuleiro or use a combination of implode() and array_map().

now have a problem with relation.

in produto model

        'precos' => array(self::HAS_MANY, 'Preco', "id_produto"),

precos model

        'produto' => array(self::BELONGS_TO, 'produto', 'id_produto'),

i have records in precos but nothing is returned.

can you help me?

"precos" => array(

        'name' => 'precos',


        'type' => 'raw',


        'value' => array($this, 'gridGroupedPrice')


    ),

protected function gridGroupedPrice($data, $row) {

    if ($this->_precos != $data->precos) {


        $this->_precos = $data->precos;


        return $data->precos;


    } else


        return 'nada';


}