Relations set BELONGS_TO but table join don't call foreign key




'music_artist'=>array(self::BELONGS_TO, 'MusicArtist', 'mu_id'),






     $model = Music::model()->findByPk(125);

     $artists = $model->music_artist;




SQL: SQLSTATE[HY000]: General error: 10007 An object or column name is missing or empty. 

For SELECT INTO statements, verify each column has a name. 

For other statements, look for empty alias names. 

Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name. [10007] (severity 5) [(null)]. 

The SQL statement executed was: 

SELECT [music_artist].[mu_id] AS [t1_c0], [music_artist].[art_ids] AS [t1_c1] 

FROM [dbo].[music_artist] [music_artist] 

WHERE ([music_artist].[]=:ypl0) 

Could you show structure of your both tables and relation() method in MusicArtist model?

Thanks Jampire!

I had just resolved this problem, i change funtion relations follows:




	public function relations()

	{

	     return array(

                   'music_artist'=>array(self::MANY_MANY, 'MusicArtist'            						

            						,''

            						, 'on' => 't.art_id=ma.art_ids'

            						,"alias" => "ma"

            				),

				);

	}



in class Music and Artist and I worked :).

But now i meet problem that my table (music_artist) havent primary key so have bug:

[color="#4169E1"]Invalid argument supplied for foreach() [/color]

In file: yii\framework\db\ar\CActiveFinder.php(841)




$pk=array();

841             foreach($this->_pkAlias as $name=>$alias)

842             {

843                 if(isset($row[$alias]))

844                     $pk[$name]=$row[$alias];

845                 else    // no matching related objects

846                     return null;

847             }

848             $pk=serialize($pk);



Same this topic: how to use CJoinElement on a table without primaryKey in database

Now I read and try fix this problem.

Thanks