Relations, Table With 3 Foreign Keys

Hello,

i have a table t_tarifsVente with 3 foreign key

  • fk_personne

  • fk_projet

  • fk_tache

Since my model Ttache i define a relation :




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

             'TachesActif' => array(self::MANY_MANY, 'TTarifsvente', 

                't_tarifsvente(fk_tache,fk_projet,fk_personne)',           

                'order'=>'titre'),

		);

	}



but in fact I would like this relation :




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

             'TachesActif' => array(self::MANY_MANY, 'TTarifsvente', 

                't_tarifsvente(fk_tache,fk_personne)',           

                'order'=>'titre'),

		);

	}



With this solution, I get this error :

in the model TProject, I have this relation:




return array(

            'ProjetsActif' => array(self::MANY_MANY, 'TTarifsvente', 

                't_tarifsvente(fk_projet,fk_personne)',

                'condition'=> 'fk_statut ='.Yii::app()->params->statutsProjet,

                'order'=>'acronyme'),


		);



and it’s work.

Someone know how can I have the same relation as r in tTache?

Thaks

Nath

I think the problem here is a misconception of MANY_MANY relations.

If you want to create a MANY_MANY relation you need 3 tables: 2 master tables and one relational tables.

You can create/add the MANY_MANY statement in the 2 master tables only.

Regards.

Let me give you more details ofr your particular needs, you may need something like this in the model Tache:





public function relations()

        {

                // NOTE: you may need to adjust the relation name and the related

                // class name for the relations automatically generated below.

                return array(

             'TachesActif' => array(self::MANY_MANY, 'TPersonne', 

                't_tarifsvente(fk_tache,fk_personne)',           

                'order'=>'titre'),

                );

        }



Hope this helps.

yes I certainly dont’t understand well relation.

I tried your exemple but it’s doesn’t work.

so I Have :

t_tarifsVente

  • fk_personne

  • fk_projet

  • fk_tache

t_taches

  • tache_id

  • fk_projet

t_personnes (in a other database)

  • personnes_id

t_projets

  • projet_id

I would like to retrieve all tache for ONE specific Personne and ONE specific projet, but I must to find the keys in the table t_tarifsVente.

So I tried that :




$listData = CHtml::listData(TTaches::model()->with('TachesActif')->findAll('fk_projet=:projetId AND TachesActif.fk_personne=:personnesId',

array(':projetId' => $fk_projet,':personnesId' => $fk_personne)), 'tache_id', 'titre');