Cakephp - 查找线程

发布于 2024-09-28 01:37:41 字数 300 浏览 2 评论 0原文

我有一个推文表,用于存储推文及其回复,例如此

推文(id,parent_id,tweet_message,time)

,其中如果是推文,则parent_id是自ID,如果是回复,则是父ID。如何进行查找以提取 id =parent_id 的推

文示例:

tweet(1, 1, '我的名字是 Harsha', 'time')parent_id = id 因为它是一条推文而不是回复 tweet(2, 1, 'Hello Harsha', 'time') Parent_id = 1 告诉它对 id = 1 的推文的回复

i have a tweet table that stores tweets and its replies like this

tweet(id, parent_id, tweet_message, time)

where parent_id is a self id if its a tweet and is of parent id if its a reply. how to do a find to pull out tweets where id = parent_id

example:

tweet(1, 1, 'My name is Harsha', 'time') parent_id = id since its a tweet and not a reply
tweet(2, 1, 'Hello Harsha', 'time') parent_id = 1 which tells its a reply to the tweet with id = 1

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

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

发布评论

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

评论(2

何止钟意 2024-10-05 01:37:41

为什么不使用树行为

Yarek T 的建议可能会起作用,但仅适用于一个级别。

Why don't you use the Tree behaviour?

Probably this suggested from Yarek T will work but only for one level.

ζ澈沫 2024-10-05 01:37:41

理论上这应该可行。查看 SQL 调试日志以了解它在出现任何错误时会执行什么操作

$conditions = array(
    'Tweet.id = Tweet.parent_id'
    );
$tweets = $Tweet->find('all', $conditions);

或者如果您正在查找特定的 ID,

$conditions = array(
    'Tweet.id' => 1,
    'Tweet.parent_id' => 1
    );
$tweets = $Tweet->find('all', $conditions);

则可以使用 MySQL <> not 运算符来搜索所有内容非根推文

$conditions = array(
    'Tweet.id' => 1,
    'Tweet.parent_id <>' => 1
    );
$tweets = $Tweet->find('all', $conditions);

'Tweet.id <> = Tweet.parent_id'

This should theoretically work. Look at the SQL Debug log to find out what it does if there are any errors

$conditions = array(
    'Tweet.id = Tweet.parent_id'
    );
$tweets = $Tweet->find('all', $conditions);

Or if you are looking for a specific ID you can do

$conditions = array(
    'Tweet.id' => 1,
    'Tweet.parent_id' => 1
    );
$tweets = $Tweet->find('all', $conditions);

you can use MySQL <> not operator to search for all nonroot tweets

$conditions = array(
    'Tweet.id' => 1,
    'Tweet.parent_id <>' => 1
    );
$tweets = $Tweet->find('all', $conditions);

or

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