Magento,将计算的自定义字段添加到查询中以供以后使用
我需要在查询中添加一个自定义列。我已经看到很多关于在网格上添加自定义列的问题,这不是问题。但我无法在模型中不存在的select子句上添加新字段。这是我的密码: 我的Magento,将计算的自定义字段添加到查询中以供以后使用,magento,magento-1.7,Magento,Magento 1.7,我需要在查询中添加一个自定义列。我已经看到很多关于在网格上添加自定义列的问题,这不是问题。但我无法在模型中不存在的select子句上添加新字段。这是我的密码: 我的\u prepareCollection()函数中有以下代码片段: $collection = Mage::getModel('banners/bannersadmin')->getCollection(); $collection->getSelect() ->join(array("T"=>
\u prepareCollection()
函数中有以下代码片段:
$collection = Mage::getModel('banners/bannersadmin')->getCollection();
$collection->getSelect()
->join(array("T"=>$this->_bannersadminTable), "main_table.banner_start_date BETWEEN T.banner_start_date AND T.banner_end_date", array())
->where("main_table.bannerID < T.bannerID");
var_dump((string) $collection->getselect());
我认为您可以将
Zend\u Db\u Select::columns()
方法与Zend\u Db\u Expr
类结合使用。例如:
$select->columns(array(
'my_value' => new Zend_Db_Expr('1')
));
我认为您可以将
Zend\u Db\u Select::columns()
方法与Zend\u Db\u Expr
类结合使用。例如:
$select->columns(array(
'my_value' => new Zend_Db_Expr('1')
));
已经尝试过了,会再尝试一次…它很有效!看来我以前的测试不正确。谢谢,我真的被它卡住了。如果我想在查询中修改这个值呢?我的意思是,一旦它被执行,我想输出
2
,而不是1
?我想您可以使用$select->getPart(Zend\u Db\u select::COLUMNS)
-这将返回$select对象中的所有列。尝试修改它们,然后使用$select->columns($yourArray)
重新设置。已经尝试过,将再次尝试…它可以工作!看来我以前的测试不正确。谢谢,我真的被它卡住了。如果我想在查询中修改这个值呢?我的意思是,一旦它被执行,我想输出2
,而不是1
?我想您可以使用$select->getPart(Zend\u Db\u select::COLUMNS)
-这将返回$select对象中的所有列。尝试修改它们,然后使用$select->columns($yourArray)
$select->columns(array(
'my_value' => new Zend_Db_Expr('1')
));