# How would I construct this validation rule?

**URL:** <https://www.ruby-forum.com/t/how-would-i-construct-this-validation-rule/144960>\
**Category:** Rails\
**Created:** [August 4, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/how-would-i-construct-this-validation-rule/144960 "2008-08-04T19:11:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 4, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/how-would-i-construct-this-validation-rule/144960/1 "2008-08-04T19:11:15Z")

</div>

Hi, I have this model,

class EcOrder \< ActiveRecord::Base  
has\_many :ec\_line\_items  
validates\_associated :ec\_line\_items  
…  
end

and what I want to do is construct a validation rule that says an  
order is not valid unless it has one or more line items. The error  
message would read, “An order must have at least one item.” How would  
I construct such a rule?

Thanks, - Dave
