What's the method name to validate an object before saving it?
Example: I have several related objects and want to make sure they're
all valid before saving any of them.

Is it better to do the above in a transaction?

Shawn

On Feb 20, 5:02 pm, Jeremy Evans <[email protected]> wrote:
> On Feb 20, 3:20 pm, beenimble <[email protected]> wrote:
>
> > Hello,
>
> > Is Sequel able to validate an association? I checked the docs and list
> > archives but didn't see an example of this.
>
> There's no validates_associated.  You shouldn't be associating invalid
> objects to your models, but checking that the objects themselves are
> valid before associating them (which saving them will do by default).
>
> > For example, if each Photo can have many Tags, I'd like to validate
> > the presence of at least one Tag. Should this just be handled outside
> > the model by trying to instantiate a new Tag object and then checking
> > its tag "name" value (or whatever the attribute is called)?
>
> validates_length_of :tags, :minimum=>1
>
> > Or is there some way to integrate this with the Photo model such that
> > I can validate the presence of at least one "child" (Tag) object?
>
> The above should do it.
>
> > I don't have a problem with doing it manually, I'm just wondering if
> > Sequel supports this somehow out of the box.
>
> I guess it does, though it may not be intuitive.
>
> Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to