Skip to content

IIIRR-29 Update for issue in tables and prevent answer duplication#23

Merged
etagwerker merged 2 commits into
mainfrom
IIRR-29
Sep 18, 2025
Merged

IIIRR-29 Update for issue in tables and prevent answer duplication#23
etagwerker merged 2 commits into
mainfrom
IIRR-29

Conversation

@FionaDL

@FionaDL FionaDL commented Sep 17, 2025

Copy link
Copy Markdown
Member

This PR attempts to fix the issues we are seeing with the weekly leaderboard not having the correct scores, and multiple entries being created in the db for one answer.

I also noticed that there were some issues with the way that the active record models were configured when it came to their relationships, so I updated that as well.

@@ -40,23 +40,29 @@ def handle(event)
return
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this as it was repetitive.

embeds: [ answer_embed(answer, puzzle) ],
ephemeral: true # Only the user sees this message
)
else

@FionaDL FionaDL Sep 17, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking further into this it seems as though answer should always be nil if the validation fails or the db index unique fails, so the if/else should work here.

Comment thread app/models/answer.rb
belongs_to :puzzle
belongs_to :user

validates :puzzle_id, uniqueness: { scope: [ :user_id, :server_id ] }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra layer of validation

Comment thread app/models/server.rb
@@ -1,3 +1,4 @@
class Server < ApplicationRecord
has_and_belongs_to_many :users, join_table: "users_servers"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this was working before

Comment thread app/models/user.rb
has_and_belongs_to_many :servers
has_many :servers
has_and_belongs_to_many :servers, join_table: "users_servers"
has_many :answers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove repetitive servers, I think this must have been a mistake and was supposed to be answers.

@@ -0,0 +1,5 @@
class AddUniqueIndexToAnswers < ActiveRecord::Migration[8.0]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add migration with db uniqueness for each answer

Comment thread db/seeds.rb
@@ -1,19 +1,47 @@

# db/seeds.rb

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this in the rails console I was having several issues so I updated the seed file to more closely resemble the relationships.

@ABizzinotto ABizzinotto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@etagwerker etagwerker merged commit 72ce4c5 into main Sep 18, 2025
4 checks passed
@etagwerker etagwerker deleted the IIRR-29 branch September 18, 2025 19:55
JuanVqz pushed a commit that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants