Symfony Propel Pager - 向其发送自定义 MySQL 查询的正确方法是什么?

发布于 2024-08-20 01:24:11 字数 623 浏览 5 评论 0原文

这是我需要运行的查询

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情魔剑神 2024-08-27 01:24:11

您需要在条件对象中使用 Criteria::CUSTOMaddAsColumn 的某种组合 - 显然您还需要使用 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 and addAsColumn in your criteria object - youll obviously also need to use doSelectRs (<= 1.2) or doSelectStmt (>=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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文