ardent icon indicating copy to clipboard operation
ardent copied to clipboard

Why not transparent "Unique Rules" resolve in model validation?

Open ghost opened this issue 10 years ago • 1 comments

I have my CostumersController and a Unique Rule in my Costumer model, so I want to update my model in the controller... but I can't do it with $model->save(), I have to use updateUniques()... this is little annoying, because the controller is not interested in if my model has or not Unique Rules... I think should call save() in the controller and unique rules should be resolved transparently.

But ok... forget ardent magic, lets try updating the rules in the beforeValidate hook.... wait... that's not a good idea... because the $rules are static...

So... I have no ideas now... Someone has some?

Honestly I think should be some way to set an automatic Unique Rules resolution...

Sorry if my english is not good.

ghost avatar Mar 12 '14 07:03 ghost

This can be done by editing the ardent save method, and if $record->exists == 1 build unique exclusion rules.

Like this: https://github.com/sjdaws/ardent/commit/d007d1846ae11d78549d2213f2d440e7e57d1ad0

If you want to do the same thing with validate you'll need to update that too: https://github.com/sjdaws/ardent/commit/fea2d8939ccdd215790398c8f66255117ae7f84e

sjdaws avatar Apr 02 '14 10:04 sjdaws