SSWConsulting / SSWConsulting/SSW.Rewards.Mobile

🐛 API - Using foreign keys causes unexpected behaviour

Open
#537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
37
Forks
11
PR merge metrics
No merged PRs in 30d

Description

In the ClaimSocialMediaAchievementForUser command, we tried to create a new UserAchievement, specifying the UserId and AchievementId fields. This caused a strange issue - a new User would be created with no values populated, and the UserAchievement would be saved against this user, rather than the current user (whose ID is added to the entity).

A workaround is in place that works - getting the required Achievement and User from the database and assigning the entities directly to the UserAchievement produces the desired result. However this required 3 db round trips instead of one.

Investigate cause of issue and resolve.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the ClaimSocialMediaAchievementForUser command and trace how UserId and AchievementId are assigned when creating UserAchievement. Compare that path with the existing direct-entity workaround, then verify the foreign-key path saves against the current user without creating an empty User and avoids the extra database round trips.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.