I am having problems when I define the criteria for multiple filters.
Given the table layout Org(1-n::1-n)SubCategory(1-n::1)Category I have the following code:
// model
'subCategoriesMm'=>array(self::MANY_MANY, 'Subcategory', 'org_cat_chosen(OrganizationId, SubCategoryId)'),
'subCategories'=>array(self::HAS_MANY,'OrgCatChosen','OrganizationId'),
'categories'=>array(self::HAS_MANY, 'Category', 'CategoryId', 'through' => 'subCategoriesMm.category'),
...
public function getRelatedSubCategoryNames ()
{
$out=GxHtml::listData($this->subCategoriesMm,'SubCategoryId','Name');
return implode('<br />', $out);
}
public function getRelatedCategoryNames ()
{
$out=GxHtml::listData($this->categories,'CategoryId','Name');
return implode('<br />', $out);
}
...
public function search() {
...
$criteria->compare('SubCategoryId',$this->assignedSubCategories);
$criteria->with=array('subCategories');
$criteria->together=true;
$criteria->compare('category.CategoryId',$this->assignedCategories);
$criteria->with=array('categories');
$criteria->together=true;
// view
$this->widget('zii.widgets.grid.CGridView', array(
...
'columns' => array(
array(
'name'=>'assignedCategories',
'filter'=>GxHtml::listData(Category::model()->findAll(array('order'=>'name ASC')),'CategoryId','Name'),
'type'=>'html',
'value'=>'$data->relatedCategoryNames',
),
array(
'name'=>'assignedSubCategories',
'filter'=>GxHtml::listData(Subcategory::model()->findAll(array('order'=>'name ASC')),'SubCategoryId','Name'),
'type'=>'html',
'value'=>'$data->relatedSubCategoryNames',
),
If I only use one or the other (i.e. Category or SubCategory) everything works as expected. When I try to put both into play I get the following error when filtering SubCategory
Integrity constraint violation: 1052 Column 'SubCategoryId' in where clause is ambiguous
So I take care of that by changing
$criteria->compare('SubCategoryId',$this->assignedSubCategories);
to
$criteria->compare('subcategory.SubCategoryId',$this->assignedSubCategories);
and then get the following error
Column not found: 1054 Unknown column 'subcategory.SubCategoryId' in 'where clause'.
Remember both of these work when only one is in play. Anybody have any ideas?