Ancestors and descendants of statuses
This commit is contained in:
parent
7e00a21ea6
commit
35aafdba96
3 changed files with 12 additions and 3 deletions
|
@ -76,6 +76,14 @@ class Status < ActiveRecord::Base
|
|||
m
|
||||
end
|
||||
|
||||
def ancestors
|
||||
Status.where(id: Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', self.id]) - [self])
|
||||
end
|
||||
|
||||
def descendants
|
||||
Status.where(id: Status.find_by_sql(['WITH RECURSIVE search_tree(id, path) AS (SELECT id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, path || statuses.id FROM search_tree JOIN statuses ON statuses.in_reply_to_id = search_tree.id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path', self.id]) - [self])
|
||||
end
|
||||
|
||||
after_create do
|
||||
self.account.stream_entries.create!(activity: self)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue