3

I need to build a query like

select * from table_name where '2008' >= substr(table_name.field_name,7,4);

in this query 2008 is the dynamic value. I need this to be built using Magento collection addFieldToFilter function.

Thanks in advance

1

you can inject collection in construct

public function __construct(\vendor\Module\Model\ResourceModel\CollectionFactory $collectionFactory){
$this->collectionFactory=$collectionFactory;
}

public function customMethod(){
$collection=$this->collectionFactory->create();
$collection->getSelect()->where(''2008' >= substr(table_name.field_name,7,4)');
         }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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