On Thursday, August 3, 2017 at 8:35:28 AM UTC-7, Mike Pastore wrote:
>
> Hi Jeremy,
>
> Kind of an oddball question, but if I have a validation on a belongs-to
> relationship (e.g. many_to_one :foo), the raised error points to the
> foreign key column (e.g. :foo_id). Is there any way to configure the
> validations plugin(s) to point to the relationship itself (e.g. :foo)
> instead of the FK? If not, would it be possible to add such functionality?
>
It's not difficult to do so yourself, maybe via something like this:
def after_validation
super
errors.keys.each do |column|
if assocs = model.autoreloading_associations[column]
assocs.each{|a| errors[a] = errors.delete(column)}
end
end
end
This doesn't handle composite key relationships, though.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.