Propel ORM - SELECT ... WHERE col1 = col2
我一直在尝试将我正在处理的项目移植到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 = 0
和 parent 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用自定义条件来通过 propel 实现此类查询:
自定义条件允许您在 WHERE 子句中编写自定义代码。在这种情况下,Criteria#add 的第一个参数并不重要(它根本不会被 propel 使用),但为了可读性,我们将其放入正在查询的列中。
You need to use a custom criteria to achieve such a query with propel:
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.
怎么样
至少要写得更少并且似乎更具可读性。
在相当复杂的标准下为我工作。
注意:
$criteria->where()
,通过AND
组合条件。如果您需要通过
OR
组合自定义条件,则需要使用$criteria->orWhere()
。What about
At least less to write and seems to be more readable.
Worked for me in rather complex criteria.
NOTE:
$criteria->where()
, combines conditions throughAND
.If you need custom criteria to be combined through
OR
, you need to use$criteria->orWhere()
.