我知道我们可以使用它从 magento 模型集合中获取 sql 查询,
getSelect();
但我只能从模型集合中获取查询,而不能在其他模型中使用,或者可能是我不知道如何使用它。
这里我想知道这背后运行的是什么查询,
$productModel = Mage::getModel('catalog/product')->getCollection();
$attr = $productModel->getResource()->getAttribute("color");
if ($attr->usesSource()) {
echo $color_label = $attr->getSource()->getOptionText("28");
}
如果我用这个,
echo $productModel->getSelect(); exit;
我只得到查询的一部分,比如,
SELECT `e`.* FROM `catalog_product_entity` AS `e`
更新:
这是我的完整代码,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$productModel = Mage::getModel('catalog/product')->getCollection();
$attr = $productModel->getResource()->getAttribute("color");
if ($attr->usesSource()) {
$color_label = $attr->getSource()->getOptionText("28");
}
$productModel->printlogquery(true);exit;
请帮帮我,
最佳答案
您的订单条件在查询中不可见。您的订单未显示的原因是订单是在 load() 方法期间添加到查询中的。
参见 Varien_Data_Collection_Db::load()
尝试调用 load(true)
以查看包含 order by 子句的完整 SQL。
$productModel->load(true);
$productModel->printLogQuery(true);
希望对您有所帮助。
关于mysql - 从集合模型中获取 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26585397/