开发者

Cakephp - find thread

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


Why don't you use the Tree behaviour?

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


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜