Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProjectLike Infinite Project References #341

Closed
Maxvanhattum opened this issue Dec 9, 2020 · 5 comments · Fixed by #351
Closed

ProjectLike Infinite Project References #341

Maxvanhattum opened this issue Dec 9, 2020 · 5 comments · Fixed by #351
Labels
bug Something isn't working

Comments

@Maxvanhattum
Copy link
Contributor

Describe the bug
In the Models Project class, a list of ProjectLike is present. However in ProjectLike there is again a reference to the aforementioned Project, essentially creating an infinite chain. Moreover in ProjectLike there is redundant information in the properties, a 'CreatorOfProject' User property is present, while this is already in the parent Project entity.
Also the user that actually made the like is only referenced by an Integer property 'UserId', this should probably also have the whole User Entity as a property.

To Reproduce
Steps to reproduce the behavior:

  1. Open the solution.
  2. Go to class library 5_models
  3. Open Project.cs
  4. Open ProjectLike.cs

Expected behavior
Code should be DRY and follow SOLID principles.

@Maxvanhattum Maxvanhattum added the bug Something isn't working label Dec 9, 2020
@ghost
Copy link

ghost commented Dec 9, 2020

I would like to add that this is also the case with the User class. When the user likes his own project the ProjectLike class will reference the CreatorOfProject which contains a list of ProjectLikes referencing back to the ProjectLike with the user.

@ghost
Copy link

ghost commented Dec 9, 2020

I will be refactoring the ProjectLike class to:
class ProjectLike { public int Id { get; set; } public int ProjectId { get; set; } public int UserThatLikedId { get; set; } public DateTime Date { get; set; } } so there won't be any references.

@ghost ghost self-assigned this Dec 9, 2020
@Brend-Smits Brend-Smits added this to To do in Sprint 8 - Backend via automation Dec 15, 2020
@ghost
Copy link

ghost commented Jan 6, 2021

Okay, I've finnaly come to the conclusion that this isn't a bug that needs to be fixed.
The objects referencing itself is part of the database design to create a Many to Many relationship. The other method would be to do something along the lines of this:

class Object1 
{
  public int Id { get; set; }
  public Object2 Object2 { get; set; } 
}

class Object2
{
  public int Id { get; set; }
  public Object1 Object1 { get; set; } 
}

class Object1Object2 
{
  public int Object1Id { get; set; }
  public int Object2Id { get; set; }
}

That being said, why isn't this a bug? There's 2 reasons:

  • First of all, the expected behaviour is that it should follow SOLID and DRY principles, but this issue doesn't come up in the SOLID and DRY issues. Nowhere in SOLID states that objectA inside an objectB inside objectA is any issue. DRY means "Don't Repeat Yourself", even though the word "Repeat" sounds like it fits in this case, it does not. The actual principle of DRY does not apply here, so doesn't SOLID.
  • Secondly, the problem would be that the program would crash because it's referencing itself infinitely. Except luckily there's Lazy Loading in C#. More on that you can find at "https://thinkdotnet.wordpress.com/2017/10/26/lazy-loading/" under the section "Varieties->Ghost".

@ghost ghost closed this as completed Jan 6, 2021
Sprint 8 - Backend automation moved this from To do to Done Jan 6, 2021
@niraymak
Copy link
Member

niraymak commented Jan 9, 2021

Reopened this issue because naming is not right. CreatorOfProject attribute is actually the one who likes the project.

@niraymak niraymak reopened this Jan 9, 2021
Sprint 8 - Backend automation moved this from Done to In progress Jan 9, 2021
@Maxvanhattum
Copy link
Contributor Author

Okay, I've finnaly come to the conclusion that this isn't a bug that needs to be fixed.
The objects referencing itself is part of the database design to create a Many to Many relationship. The other method would be to do something along the lines of this:

Ah yes my bad, seems like entity framework uses bidirectional relationships as its standard when using this kind of code first approach. Good catch.

Sprint 8 - Backend automation moved this from In progress to Done Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants