Let’s suppose you created an drop down type custom product attribute which has a source model as in Create drop down product attribute in Magento 2 blog.
Even when we set used_in_product_listing=1 the attribute “attribute_code” will not be added to the flat table because we are using source model for this attribute.
So to add this attribute to the flat table we need to implement a method in Company\Module\Model\Config\Source\Options class as shown below,
public function getFlatColumns() { return ['attribute_code'=>['type'=>'integer', 'length'=>2]]; }
Thank you for reading the blog. Please let me know by commenting if you face any issue.
Happy Coding