Propel ORM - SELECT ... WHERE col1 = col2

发布于 2024-10-03 13:12:08 字数 598 浏览 0 评论 0原文

我一直在尝试将我正在处理的项目移植到PropelORM。到目前为止一切都很好。

然而,我在一个表中设置的树结构遇到了问题。

几乎如果 ID = PARENTID 那么它就是一个根。 例如。

ID | NAME | PID
0  | ZERO | 0  
1  | ONE  | 1  
2  | TWO  | 1  
3  | THREE| 3  

一和二实际上是根。

我尝试了类似的操作

$res_crit = new Criteria();  
$res_crit->add(PropertyTypePeer::ID, PropertyTypePeer::CONVERTEDID, Criteria::EQUAL);  
$result = PropertyTypePeer::doSelect($res_crit, Propel::getConnection('system'));  

,但它只返回一行,其中 ID = 0parent id = 0。

有什么想法吗?

I have been trying to port project im working on to PropelORM. So far so everything has been great.

However I've ran into problems with a tree structure that we have setup in one of our tables.

Pretty much if ID = PARENTID then its a root.
eg.

ID | NAME | PID
0  | ZERO | 0  
1  | ONE  | 1  
2  | TWO  | 1  
3  | THREE| 3  

One and two are actually roots.

I tried something like this

$res_crit = new Criteria();  
$res_crit->add(PropertyTypePeer::ID, PropertyTypePeer::CONVERTEDID, Criteria::EQUAL);  
$result = PropertyTypePeer::doSelect($res_crit, Propel::getConnection('system'));  

but it only returns one row where where ID = 0 and parent id = 0.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

独自唱情﹋歌 2024-10-10 13:12:13

您需要使用自定义条件来通过 propel 实现此类查询:

$res_crit->add(PropertyTypePeer::ID, PropertyTypePeer::ID.' = '.PropertyTypePeer::CONVERTEDID, Criteria::CUSTOM);

自定义条件允许您在 WHERE 子句中编写自定义代码。在这种情况下,Criteria#add 的第一个参数并不重要(它根本不会被 propel 使用),但为了可读性,我们将其放入正在查询的列中。

You need to use a custom criteria to achieve such a query with propel:

$res_crit->add(PropertyTypePeer::ID, PropertyTypePeer::ID.' = '.PropertyTypePeer::CONVERTEDID, Criteria::CUSTOM);

A custom criteria allows you to write custom code in your WHERE clause. In such a case, the first argument of Criteria#add does not matter (it won't be used by propel at all) but we're putting in the column we're querying on for readability's sake.

2024-10-10 13:12:13

怎么样

$res_crit->where(PropertyTypePeer::ID.' = '.PropertyTypePeer::CONVERTEDID);

至少要写得更少并且似乎更具可读性。

在相当复杂的标准下为我工作。

注意: $criteria->where(),通过AND组合条件。

如果您需要通过OR组合自定义条件,则需要使用$criteria->orWhere()

What about

$res_crit->where(PropertyTypePeer::ID.' = '.PropertyTypePeer::CONVERTEDID);

At least less to write and seems to be more readable.

Worked for me in rather complex criteria.

NOTE: $criteria->where(), combines conditions through AND.

If you need custom criteria to be combined through OR, you need to use $criteria->orWhere().

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