Has_many relationship - specify how quantity (how many)


Is there any way to specify a a validation rule or something for the
"has_many’ relationship so that it would count the related objects?

For e.g. I want my Foo object to have maximum of 5 Bar objects in
has_many relationship.


I suppose you could write a custom validator to ensure that no more than
child objects exist.

On Sun, Jul 5, 2009 at 5:12 PM, Michal B. <

validates :bar_limit

def bar_limit



On Jul 5, 2:12 pm, Michal B. [email protected]