I would like to get the id’s of posts that a specific user has liked. How can I do this?
You can find that with the Data Explorer Plugin with a query like this:
-- [params] -- string :username WITH sample_user AS ( SELECT u.id FROM users u WHERE u.username = :username ) SELECT p.topic_id, pa.post_id, pa.created_at AS liked_at FROM post_actions pa JOIN posts p ON p.id = pa.post_id WHERE pa.post_action_type_id = 2 AND pa.user_id = (SELECT id FROM sample_user) ORDER BY pa.created_at DESC
If you need to see the actual
id, instead of a link to the topic and an excerpt of the post, change the line
pa.post_id AS id
To get the post_ids with an ActiveRecord query, do something like this, with the
user_id of the user you are looking for:
PostAction.where(post_action_type_id: 2, user_id: 1).pluck(:post_id)
this looks really cool!
Specifically, I was wondering if there was a way to get this through api