I would like to get the id’s of posts that a specific user has liked. How can I do this?
AI-generated summary
The discussion revolves around retrieving the IDs of posts that a specific user has liked. rodeezy asks how to achieve this, and simon provides a solution using the Data Explorer Plugin with a SQL query, explaining how to modify it to return post IDs directly. simon also suggests an ActiveRecord query for direct database access. rodeezy then asks if this can be done via the API, and simon confirms it’s possible by querying the Data Explorer through the API, referencing a relevant guide.
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
to
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
You can query the Data Explorer through the API. Take a look at Access to query data from API endpoints.