sondieuars
(Sonths2009)
February 24, 2012, 2:15am
1
Hi, i had problem but couldnt resolve.
I have 2 table ( music and music_artist ) and two class Music, MusicArtist.
In Music class, i create relation:
'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)
Here, [size="5"][color="#FF0000 "][music_artist].[]=:ypl0[/color][/size] not call foreignkey(mu_id), I dont known how is that, could you help me resolve this problem. Thank so much!
Jampire
(Jampire Blr)
February 24, 2012, 7:20am
2
Could you show structure of your both tables and relation() method in MusicArtist model?
sondieuars
(Sonths2009)
February 24, 2012, 8:00am
3
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