Validates Presence of Child Object

Hi Folks,

Is there a validation in rails that works on child objects that are
declared as associations.

eg: I have an Order class and a LineItem class, where Order has_many
:line_items. Is there a validation that would allow me to ensure that
an order is only valid when it has at least on line item?

Thanks,
Scott

On 9/22/06, sbellware [email protected] wrote:

Is there a validation in rails that works on child objects that are
declared as associations.

eg: I have an Order class and a LineItem class, where Order has_many
:line_items. Is there a validation that would allow me to ensure that
an order is only valid when it has at least on line item?

Sure, validates_size_of :line_items, :minimum => 1

jeremy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs