0

I have a classical Reader/Subscription/Newspaper schema, and I want that there's never 2 Subscriptions with the same pair of Reader x Newspaper.

To reassure this, I'm checking during the Subscription insertion whether there's already a Subcription with such keys. However a colleague has told me that I should move this validation outside of the Model, as it should only run SQL commands.

Is this how Models in MVC should behave? They should only contain SQL related commands?

Nilo Araujo
  • 725
  • 6
  • 15
  • 1
    From a database perspective you should create a unique constraint on Reader/Newspaper columns in the database table. Then nothing can put invalid data into your database. Remember other things besides your app might put data in here, so in IMHO it's important to defined these things at the _database_ level, not in an external app – Nick.Mc Jul 12 '17 at 01:56
  • Thanks, you are right. For anyone else looking here it is how to https://stackoverflow.com/questions/12763726/mysql-make-a-pair-of-values-unique – Nilo Araujo Jul 12 '17 at 02:00

0 Answers0