On Monday, January 13, 2014 6:52:00 AM UTC-8, Andrew Hacking wrote:
>
>
> I would like to be able to quash exceptions and just examine model errors. 
> I can almost do this when using the nested attributes plugin due to the way 
> it avoids validating on save and instead uses an 
> after_validation_hook/after_save_hook (but this has problems for (eg 
> automatic) validations that check foreign key presence on new parent 
> records).
>

Well, I don't think those problems are solveable.  If you have a validation 
the depends on the foreign key being set, and you can't know the foreign 
key value until after the parent object is saved, you can't validate the 
associated objects without saving the parent object first.
 

> I share the backward compatibility concern but I would prefer the 
> behaviour of the core option to follow the principle of least surprise.  I 
> regard the current behaviour as somewhat surprising. This could be fixed 
> with documentation and a plugin similar to some of what nested attributes 
> does, but it does feel a bit like adding a patch plugin to get correct 
> intent.
>

I think the backwards compatibility issue is significant enough that 
changing existing behavior cannot be made without a major version bump 
(e.g. until Sequel 5), if it even can be made at all.  Changing this 
behavior breaks code in bad ways, equivalent to silently swallowing 
exceptions.
 

> Perhaps the middle ground is to do it in core using a hook like 
> nested_attributes does so that model errors can be accumulated and examined 
> on an error, and allowing a special raise_on_failure/raise_on_save_failure 
> value of :none/:never as well as preserving the current falsey/truthy value 
> behaviour.
>

I'm not sure how this could be done without reimplementing much of 
nested_attributes in core (which I don't want to do), but I'll consider 
this approach it if could be done in a simple way.
 

> Ultimately I don't mind how we get the behaviour, I'd just like to avoid 
> raising exceptions and examine model.errors as this works nicely when 
> implementing JSON API's or handling complex form errors in web server code.
>

FWIW, I'm not sure why you can't use nested_attributes.  The problem you 
have with nested attributes is inherent, it's not specific to the 
implementation of nested_attributes. nested_attributes is designed 
specifically for the use case of handling associated objects and combining 
validation errors.

As an aside, I realize using exceptions for flow control is bad, but I 
think the returning false from save (and similar methods) is worse.  The 
former makes it just slightly more difficult to deal with bad records.  The 
latter makes it easy to silently ignore errors.  For that reason, I 
discourage setting of raise_on_save_failure = true.

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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to