# Contest participant get a Badge

**URL:** https://meta.discourse.org/t/contest-participant-get-a-badge/32769
**Category:** Support
**Created:** [2015年九月1日 08:29 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769 "2015-09-01T08:29:32Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Imperator](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/imperator/32/45089_2.png) [@Imperator](https://meta.discourse.org/u/Imperator)
#### Post date: [2015年九月1日 08:29 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/1 "2015-09-01T08:29:32Z")

</div>

Hi,

I make a Contest and will that the participant gain a Badge for participation.  
The participant must create a post on a certain topic in a certain categorie.

Also i search here for the something and i found this…

> [@What is the bug reporter badge?](https://meta.discourse.org/t/what-is-this-bug-reporter-badge/17987):
>
> You may or may have not noticed this new badge: [https://meta.discourse.org/badges/114/bug-reporter](https://meta.discourse.org/badges/114/bug-reporter) What I find super exciting about it is that there are zero plugins needed, I crafted it using our badges UI. Not only does it grant the badge daily, it will also grant it after one of the team “likes” a bug. It runs the following badge query: SELECT p.user\_id, min(p.created\_at) granted\_at, MIN(p.id) post\_id FROM badge\_posts p JOIN topics t ON t.id = p.topic\_id JOIN post\_actions pa ON pa.post\_id…

I only must change a little bit the code…

```
SELECT p.user_id, min(p.created_at) granted_at, MIN(p.id) post_id
FROM badge_posts p
JOIN topics t ON t.id = p.topic_id
JOIN post_actions pa ON pa.post_id = p.id AND 
      post_action_type_id = (
                SELECT id FROM post_action_types WHERE name_key = 'like'
       ) AND 
       pa.user_id IN (
           SELECT gu.user_id
           FROM group_users gu
           WHERE gu.user_id = ( SELECT id FROM users WHERE username ilike 'Username' ) 
       )
WHERE category_id = (
  SELECT id FROM categories WHERE name ilike 'Casual Contest'
) GROUP BY p.user_id

```

with that i have only to Like all post of the participant.  
And it Work!

**BUT…**

for testing that that work i have like a post and it work. But if i Disslike that post the post stays in that query.

Or have a better Idea for that?  
Every month is a new Contest and every contest the participant have to post to a other certain topic.

regards,  
Imperator

---

<div class="post-metadata">

### Author: ![Snazzamazza](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Snazzamazza](https://meta.discourse.org/u/Snazzamazza)
#### Post date: [2015年九月1日 10:42 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/2 "2015-09-01T10:42:03Z")

</div>

Very interesting, nice job on changing the code. I am a coder, but I am not that advanced yet!

---

<div class="post-metadata">

### Author: ![Imperator](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/imperator/32/45089_2.png) [@Imperator](https://meta.discourse.org/u/Imperator)
#### Post date: [2015年九月1日 13:12 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/3 "2015-09-01T13:12:10Z")

</div>

@sam

When i Like a post and unlike it. Its still as Like at the database?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2015年九月1日 13:14 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/4 "2015-09-01T13:14:33Z")

</div>

Why don’t you check it? Like a post, check the latest `PostAction`. Unlike the post, check the latest `PostAction`.

---

<div class="post-metadata">

### Author: ![Imperator](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/imperator/32/45089_2.png) [@Imperator](https://meta.discourse.org/u/Imperator)
#### Post date: [2015年九月1日 13:17 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/5 "2015-09-01T13:17:10Z")

</div>

I already Check this.

I have like a post. The Query Found a Post…  
Then i Unlike that and it still found on that query.

but why or how i make that is not still found if i unlike that post.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2015年九月1日 13:23 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/6 "2015-09-01T13:23:48Z")

</div>

> [@Imperator](#):
>
> I have like a post. The Query Found a Post…  
> Then i Unlike that and it still found on that query.

Were they the exact same record? Are you sure there weren’t any differences?

---

<div class="post-metadata">

### Author: ![Imperator](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/imperator/32/45089_2.png) [@Imperator](https://meta.discourse.org/u/Imperator)
#### Post date: [2015年九月1日 13:33 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/7 "2015-09-01T13:33:34Z")

</div>

I think i am sure…

Here is a GIF

And… by the frist user i like him again. After that i cant unlike… again maybe a bug?  
That is the reason why i like the post of a other user.

 ![](https://global.discourse-cdn.com/meta/original/3X/7/6/7663e24b86642d0039afb257c518adb44adb5a6a.gif)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2015年九月1日 13:37 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/8 "2015-09-01T13:37:01Z")

</div>

You have to check that the `PostAction` (the ❤) hasn’t been deleted by checking that “`pa.deleted_at IS NULL`”.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2015年九月1日 14:03 UTC](https://meta.discourse.org/t/contest-participant-get-a-badge/32769/9 "2015-09-01T14:03:52Z")

</div>


