0
I have a form and include a table médicos
, and this table has a field enum
where you can choose the option of cooperativa
, but I have to check on another table of cooperativa
if this doctor has a cooperativa
.
In the validation, how do I read these two tables and check whether the médico
has a cooperativa
, because otherwise I have to show a message saying that this doctor does not have cooperativa
.
you use which database ?
– Victor
yes, I access through active admin.
– eduardo
mysql database
– eduardo
need to create a Join then, I will put as an answer to exemplify, try playing in mysql and if it works as you want it will help you now
– Victor
private def validate_presence_of_cooperatives errors.add("Cooperative", "There Must Be a Cooperative for this Specialist") if Specialties.Empty? end
– eduardo
You need to show the user, in the form, doctors who have no cooperative associate? Because if not, you in the controller would already do something like: @medicos = Medico.com_cooperativa. That way you don’t have to worry about validation. You would only make a Scope in the model of doctor that would return you a collection of doctor that has cooperative
– Sullyvan Nunes