How to validate a 1-n relationship

Hia all,

I have a model A which has many B relationships (1-n). Then I create an associative class A_B which contains (id, a_id,b_id)

A must be create with at least one link to B

In the form which create the A model i get all B instance and i propose a table of check boxes.

But what is the best way to validate the A model creation (with the constraint of having at least one relationship with B.)

1- Shall I overwrite validate in the A model. In which i collect all checkboxes and perform test (one at least mut be checked)

2- Shall I write a specific Validator class ?

3- or ??

Please, hints will be appreciated.

Thanks

I think this kind of validation belong more to the controller.

Model validation is more atomic in the sense that (generally) it check if the data is compatible with model filed

Making such validation in the model implies that the model become aware of other model data which is a bit weird.

Consider also that you must do the check before you save in A, so the controller I think is the best place.

Thx to your reply,

but i disagree. Main objective of the controller is to route. And nothing more.

I guess that this validation must belong to model or … but not in controller.

nevertheless thx for your help