Validations on models for a sports league
The schema question has been asked before and the below is a snapshot of what I believe is right. The issue I'm having now is getting a validation to work so 开发者_JS百科that the same two players don't play more than once in a division. For starters we have three different inserts happening:
- Create match
- Create result_1 (whoever submitted)
- Create result_2
So the results can come in any order (dependent on who submitted) and aren't in the same record which would have made looking for a duplicate easier.
Match
- division_id
Result
- match_id
- player_id
- score
Is the only way around this to write a separate validation by taking the player_id's and comparing them in the database?
If the data you're validating against lives in the database, then you need to go to the database, yes.
精彩评论