Symfony Propel Pager - 向其发送自定义 MySQL 查询的正确方法是什么?
这是我需要运行的查询
SELECT REPLACE(REPLACE(SUBSTRING_INDEX(LOWER(table.url), '/', 3), 'www.', ''), 'http://', '') AS 域 FROM 表 GROUP BY 域
但是我'我无法将这样的查询作为条件传递给 Propel 寻呼机。我希望这会起作用。
$criteria->addSelectColumn('SUBSTRING_INDEX(' . TablePeer::URL . ', \'/\', 3) AS 表');
但不幸的是事实并非如此。我有什么想法可以使用标准方法通过这个吗?
更新
对于那些感兴趣的人,这就是最终的工作,谢谢!
$criteria->addAsColumn('domain', 'SUBSTRING_INDEX(' . TablePeer::URL . ', \'/\', 3)');
$criteria->addGroupByColumn('domain');
Here is the query I need to run
SELECT REPLACE(REPLACE(SUBSTRING_INDEX(LOWER(table.url), '/', 3), 'www.', ''), 'http://', '') AS domain FROM table GROUP BY domain
But I'm having trouble passing a query like this to the Propel pager as criteria. I was hoping this would work.
$criteria->addSelectColumn('SUBSTRING_INDEX(' . TablePeer::URL . ', \'/\', 3) AS table');
But unfortunately it doesn't. Any ideas how I could pass this using a criteria method?
UPDATE
For those interested, this is what ended up working, thanks!
$criteria->addAsColumn('domain', 'SUBSTRING_INDEX(' . TablePeer::URL . ', \'/\', 3)');
$criteria->addGroupByColumn('domain');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在条件对象中使用
Criteria::CUSTOM
和addAsColumn
的某种组合 - 显然您还需要使用doSelectRs
(<= 1.2) 或doSelectStmt
(>=1.3) 我不确定确切的公式是什么,但这可能会让您走向正确的方向(注意该链接适用于 1.2,因此请根据需要更新 sysntaxt/api 1.3 或 1.4)。http://stereointeractive.com /blog/2009/07/21/propel-criteria-on-custom-columns-with-addascolumn/
You need to use some combination of
Criteria::CUSTOM
andaddAsColumn
in your criteria object - youll obviously also need to usedoSelectRs
(<= 1.2) ordoSelectStmt
(>=1.3) Im not sure what the exact formulation would be but this might get you in the right direction (note the link is for 1.2 so update sysntaxt/api as needed for 1.3 or 1.4).http://stereointeractive.com/blog/2009/07/21/propel-criteria-on-custom-columns-with-addascolumn/