I’ve searched through SO quite a bit for this, but I haven’t seen a question for what I’m looking for specifically. Simple problem really. I have a form that creates a project, based on a Project model. The user must also input associated images (one-to-many Image). The validations within the Models works fine, but what I was hoping cake would do for me was allow me to establish mandatory conditions on Project-to-Image associations. In other words, when I’m creating a Project, you must create at least one image with it. I’ve scoured the documentation and haven’t seen how this is done in a declarative fashion like typical validation rules. Anyone have ideas on this approach? Am I left to doing this type of validation in the controller?
Thanks!
So I believe I’ve come up with a sensible enough solution for this, though always open for other suggestions. In the case of my primary Project model, I placed a hidden field in the form called hasImages. When the form is submitted, I have a bit of js check for the necessary images. If they’re missing, this form is set to false, true otherwise. Then its simply a matter of creating a validation rule on the hasImages field in my Project model. Hope someone finds this useful.