Question

I am using grid serialization in my custom module grid.

I want to filter data using student_ids.

I have current student id.

In database student_ids save multiple student id for Ex. 1,2,3.

Now i want to filter grid current student id exists in student_ids.

I am trying this

$currentStudentId = $this->getRequest()->getParam('id');
    $collection = Mage::getModel('example/data')->getCollection()
                ->addFieldToFilter('student_ids',array('like' => '%,'.$currentStudentId));

but using this i can't get proper data because string is like this 1,2,3 here so many possibility so i can't use this please give me solution

[EDIT]

enter image description here

Was it helpful?

Solution

you can use finset sql cluse

$currentStudentId = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('example/data')->getCollection()
         ->addFieldToFilter('student_ids',array("finset"=>$currentStudentId);

basically this clause use in magento when we have multiple selection in any attribute

hope it will work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top