0

I have grid in which i try to filter a field name "seller_id" and this grid is a coming from a custom dataprovider with join of two tables.

Now the issue is these both table have same column name "seller_id" due to which it throws ambiguous column error upon filtering the column "seller_id".

2 Answers 2

0

Make use of select and alias in join might resolve your issue

3
  • already have alias but when i filter them it shows error
    – Asad Ullah
    Sep 19, 2022 at 7:39
  • Share your code Sep 19, 2022 at 7:58
  • shared my answer, thanks for the help its resolved
    – Asad Ullah
    Sep 19, 2022 at 8:37
0

write this function in dataprovider file

    /**
 * @param \Magento\Framework\Api\Filter $filter
 */
public function addFilter(\Magento\Framework\Api\Filter $filter)
{
    if($filter->getField() === 'seller_id') {
        $filter->setField("main_table.".$filter->getField());
    }
    $joinRefField = "main_table.".$filter->getField();
    if (isset($this->addFilterStrategies[$filter->getField()])) {
        $this->addFilterStrategies[$filter->getField()]
            ->addFilter(
                $this->getCollection(),
                $joinRefField,
                [$filter->getConditionType() => $filter->getValue()]
            );

    } else {
        parent::addFilter($filter);
    }
}

as you were getting column name in " $filter->getField() " so you need to modify where query using the first if condition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.