In framework/db/ar/CActiveFinder.php line 881:
else // has_many and many_many
{
// need to double check to avoid adding duplicated related objects
if($childRecord instanceof CActiveRecord)
$fpk=serialize($childRecord->getPrimaryKey());
else
$fpk=0;
// TODO
if(!isset($this->_related[$pk][$child->relation->name][$fpk]))
{
if($childRecord instanceof CActiveRecord && $child->relation->index!==null)
$index=$childRecord->{$child->relation->index};
else
$index=true;
$record->addRelatedRecord($child->relation->name,$childRecord,$index);
$this->_related[$pk][$child->relation->name][$fpk]=true;
}
}
i replace //TODO with :
//if(!isset($this->_related[$pk][$child->relation->name][$fpk]))
//{
if($childRecord instanceof CActiveRecord && $child->relation->index!==null)
$index=$childRecord->{$child->relation->index};
else
$index=true;
$record->addRelatedRecord($child->relation->name,$childRecord,$index);
$this->_related[$pk][$child->relation->name][$fpk]=true;
//}
ModelA Has_many ModelB , the pk of ModelB has many, why ingore it if isset $fpk