0

I have the following query:

SELECT `main_table`.*, `secondTable`.* FROM `table_one` AS `main_table`
LEFT JOIN `table_two` AS `secondTable` 
ON main_table.blog_id = secondTable.blog_id 
WHERE (store_id = '3') OR (store_id = '0');

Now take this query and run in CLI it Works perfect it gives all the data you need but in magento it doens't. I Think there is something preventing it but not sure. So blog_id are in both tables could be why it isn't returning so if it is how could I add alias for the columns blog_id for both tables?

UPDATE:

index.php:

public function getBlogs(sort)
    {
        if (is_null($this->blogs)) {
            $this->blogs = $this->blogCollectionFactory->create()
                ->setOrder(empty($sort)?'position':$sort, 'ASC');
             $this->blogs->getSelect()->reset(\Zend_Db_Select::WHERE)->where('secondTable.store_id = ?', $this->_storeManager->getStore()->getId())->orwhere('secondTable.store_id = ?', 0);
             echo $this->blogs->getSelect();
        }
        return $this->blogs;
    }

enter image description here

So if I don't add the last statement ->orwhere('secondTable.store_id = ?', 0) then it works but I need to return everything including those that belongs to store_id=0 hence why added but in magento doesn't like it;

index.phtml:

print_r(get_class_methods($block->getBlogs('position')));
print_r($block->getBlogs('position')->getSelect());
die;
6
  • Does store_id column available in both the tables ? Commented Jul 22, 2019 at 13:50
  • @ Abdul Pathan No Only second table Commented Jul 22, 2019 at 15:44
  • Could you please update the Magento code you are using to run the query. Also show the error it throws if any. Commented Jul 22, 2019 at 15:50
  • @AbdulPathan No error the page returns but without items I supposed getCollection() is returning array() Commented Jul 22, 2019 at 16:05
  • It would be helpful if you put your Magento code as well in the question. Commented Jul 22, 2019 at 16:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.