I have a Competition model, that has many Entry models.
[edit] Schema looks (roughly) like this:
Competition:
id INT(11)
name VARCHAR(50)
date DATETIME
Entry:
id INT(11)
competition_id INT(11)
user_id INT(11)
answer VARCHAR(50)
isWinner INT(1)
In my pickWinner view, I have a form that loops through all related entries - offering the isWinner field to allow the user to pick an entry as the winner. Saving the related model etc is pretty standard and that all works fine.
I'm trying to validate the form so that at least one of the Entry models has isWinner set to true (the user has to pick at least one winner).
I obviously can't apply the validation rule to the Entry model - as each model only knows about itself and not the values of the other models.
Only one Entry model should be set as the winner - how do I add a validation rule to Competition, so that it can detect that one of its child Entry models has isWinner set to true?