I have 1 module with model, resource model and collection. Now I can get data with SQL query: SELECT main_table.* FROM table_abc AS main_table;
I want to customize this query by adding WHERE clause (for example: WHERE 3 = 3). How can I do that?
I tried to add $this->getSelect()->where('3 = ?', 3); into _initSelect method of collection but It didn't work (When I see SQL log I realize SQL not change)
Here is my full code (Collection class):
<?php
namespace ScPortal\SubscriptionItems\Model\ResourceModel\SubscriptionItems;
use Zend\Log\Writer\Stream;
use Zend\Log\Logger;
/**
* Class Collection
*
* @package ScPortal\SubscriptionItems\Model\ResourceModel\SubscriptionItems
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'subscription_items_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(
\ScPortal\SubscriptionItems\Model\SubscriptionItems::class,
\ScPortal\SubscriptionItems\Model\ResourceModel\SubscriptionItems::class
);
}
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->where('3 = ?', 3);
}
}
spiredigital.com, but It didn't work