echo75 / my-movie-db

MIT License
1 stars 0 forks source link

#Principles Seperation of concerns - who's responsibility is it? #22

Open Dr4gon opened 1 year ago

Dr4gon commented 1 year ago

@echo75 From what I understand, u're saving the same review 2 times in different objects.

user.js

  async review(movie, review) {
    this.reviews.push(review)
    movie.Reviews.push(review)
    await this.save()
    await movie.save()
    return review
  }

To me this is flaw in the design. A review can be an independant object that holds a reference to the user and to a movie. Thus you only store a review object in the DB. I.e. only 1 operation, easier maintenance, and loose coupling.

Now if you change a review, you always have to change it in user and movie. It also might lead to dirty updates, if one or the other isn't properly updated and you retrieve the data - who's right?