Michal Burak
2009-Jul-05 21:12 UTC
has_many relationship - specify how quantity (how many)
Hi, 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. M. -- Posted via http://www.ruby-forum.com/.
James Englert
2009-Jul-05 22:44 UTC
Re: has_many relationship - specify how quantity (how many)
I suppose you could write a custom validator to ensure that no more than 5 child objects exist. On Sun, Jul 5, 2009 at 5:12 PM, Michal Burak < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > 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. > > M. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
validates :bar_limit def bar_limit ... end -eric On Jul 5, 2:12 pm, Michal Burak <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > 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. > > M. > -- > Posted viahttp://www.ruby-forum.com/.