In my model, let’s call it “questions”, I have “active” field (TINYINT). The idea is, that only one entry in that particular model can be active. So when I update one entry by checking “active” checkbox, this entry should turn into active, and the other one should turn into unactive (I mean that one which has been active before). Any idea what query should I use?
Share
some kind of toggle behavior for example.
this behavior you write makes the model
$actsAs = array('Toggable', array('field'=>'active'));and in your afterSave hook you make an updateAll call to reset all active ones to inactive (except the current id of course)
that would be the cleanest approach.
of course, you can always make a quick-and-dirty one using the models hooks itself for this.