$q = Mage::getModel('qa/post')->getCollection()->addProductFilter(1)->printLogQuery(true);
public function addProductFilter($productId)
{
$this->addFieldToFilter('qa_post_relation.product_id', $productId);
return $this;
}
エラーを返します:
a:5:{i:0;s:94:"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'qa_post_relation.product_id' in 'where clause'";i:1;s:2016:"#0 C:\xampp\htdocs\ahw\lib\Varien\Db\Statement\Pdo\Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\xampp\htdocs\ahw\lib\Zend\Db\Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 C:\xampp\htdocs\ahw\lib\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 C:\xampp\htdocs\ahw\lib\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `main_ta...', Array)
#4 C:\xampp\htdocs\ahw\lib\Varien\Db\Adapter\Pdo\Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `main_ta...', Array)
#5 C:\xampp\htdocs\ahw\lib\Zend\Db\Adapter\Abstract.php(734): Varien_Db_Adapter_Pdo_Mysql->query('SELECT `main_ta...', Array)
#6 C:\xampp\htdocs\ahw\lib\Varien\Data\Collection\Db.php(734): Zend_Db_Adapter_Abstract->fetchAll('SELECT `main_ta...', Array)
#7 C:\xampp\htdocs\ahw\app\code\core\Mage\Core\Model\Resource\Db\Collection\Abstract.php(521): Varien_Data_Collection_Db->_fetchAll('SELECT `main_ta...', Array)
#8 C:\xampp\htdocs\ahw\lib\Varien\Data\Collection\Db.php(566): Mage_Core_Model_Resource_Db_Collection_Abstract->getData()
#9 C:\xampp\htdocs\ahw\lib\Varien\Data\Collection.php(741): Varien_Data_Collection_Db->load()
#10 C:\xampp\htdocs\ahw\app\code\local\AJW\Qa\controllers\IndexController.php(25): Varien_Data_Collection->getIterator()
#11 C:\xampp\htdocs\ahw\app\code\core\Mage\Core\Controller\Varien\Action.php(419): AJW_Qa_IndexController->indexAction()
#12 C:\xampp\htdocs\ahw\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#13 C:\xampp\htdocs\ahw\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#14 C:\xampp\htdocs\ahw\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#15 C:\xampp\htdocs\ahw\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#16 C:\xampp\htdocs\ahw\index.php(87): Mage::run('', 'store')
#17 {main}";s:3:"url";s:5:"/qas/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
クエリ: SELECT main_table
.* FROM qa_posts
AS main_table
WHERE (qa_post_relation.product_id = '1') が失敗する 不明な列 'qa_post_relation.product_id' in 'where clause'
でも:
SELECT * FROM qa_posts_relation
WHERE product_id
=1
1 つの結果を返します。