选择一个不包含"e."或"main_table"的字段-Magento [英] Select a field without `e.` or `main_table` - Magento

查看:39
本文介绍了选择一个不包含"e."或"main_table"的字段-Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是我在这个论坛上提出的其他问题之一.我创建了一个自定义模块,并覆盖了审阅"模型的核心文件.它使我可以将数据保存到自定义字段电子邮件"中.但是当我尝试检索该字段的值时,它根本无法识别我的字段.

This question follows from one of my other questions on this forum. I have created a custom module and have overridden 'Review' model's core files. It allows me to save data to my custom field 'email' fine. But when I try to retrieve the values of this field, it doesn't recognize my field at all.

这是我的查询

Mage::getModel('review/review')->getCollection()
->addFieldToFilter('status_id' , '1')
->addFieldToFilter('email', $emailId)
->addFieldToSelect('email');

这就是我回声时得到的,

And this is what I get when I echo it,

 SELECT `main_table`.`email` AS `review_detail`, `detail`.`detail_id`, `detail`.`title`, `detail`.`detail`, `detail`.`nickname`, `detail`.`customer_id` FROM `review` AS `main_table` INNER JOIN `review_detail` AS `detail` ON main_table.review_id = detail.review_id WHERE (status_id = '1') AND (email = 'test@test.com')

显然,它试图从review表而不是review_detail表的main_table中选择电子邮件.有没有一种方法可以选择不带main_table前缀的email字段,或者只是更改查询以使其从review_detail表中选择email?

Its obviously trying to select email from main_table which is review table instead of review_detail table. Is there a way to select email field without main_table prefix or just change the query such that it selects email from review_detail table?

请帮帮我.我遇到过与joins有关的帖子,但不确定这是否是我的选择之一.预先感谢.

Please help me out. I have come across posts related to joins but not sure if that is one of the options in my case or not. Thanks in advance.

推荐答案

让它现在开始运行的快速方法是,我直接在代码中传递了一个SQL查询.我知道这不是正确的方法,但是我尝试做的任何事情当然都无济于事.这是我的代码:

Well the quick way to get it running for now is that I have directly passed a SQL query in the code. I know that's not the right way to do it but any thing I tried was certainly not helping. This is my code:

  $resource = Mage::getSingleton('core/resource');
  $readConnection = $resource->getConnection('core_read');
  $query = "SELECT a.review_id, b.email FROM  review AS a INNER JOIN review_detail AS b WHERE a.review_id = b.review_id AND a.status_id = 1 AND b.email = '" . $emailId. "'";  
  $results = $readConnection->fetchAll($query);

我知道这不是编写magento代码的正确方法,但是要使其快速工作,我别无选择.我会一直在寻找适当的解决方案,并在获得解决方案后对其进行修改.如果还有其他人想用Magento的方式写同样的东西,请告诉我.

I know this is not the right way to write a magento code but to get it working quickly, I had no other option. I would keep looking for a proper solution and would amend it once I get it. If anyone else could think of writing this same thing but the Magento way please let me know.

到目前为止,感谢您的帮助.

Thanks for your help so far every one.

这篇关于选择一个不包含"e."或"main_table"的字段-Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆