0

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-&gt;_init(
        \ScPortal\SubscriptionItems\Model\SubscriptionItems::class,
        \ScPortal\SubscriptionItems\Model\ResourceModel\SubscriptionItems::class
    );
}

protected function _initSelect()
{
    parent::_initSelect();
    $this-&gt;getSelect()-&gt;where('3 = ?', 3);
}

}

Spirit
  • 101
  • 1
  • check this link --- https://magento.stackexchange.com/a/88129/85907 and you want to use this function _initSelect() https://www.spiredigital.com/views/magento-2-create-model-using-joined-sql-query/ – Mohit Patel Jul 07 '20 at 05:10
  • @MohitPatel I would like the solution in spiredigital.com, but It didn't work – Spirit Jul 07 '20 at 06:28

0 Answers0