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;
}
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;
store_id
column available in both the tables ?