h.dudeness-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-03 17:18 UTC
has_and_belongs_to_many count validation
I am using the has_and_belongs_to_many association and I would like to limit the number of records that can be joined. I can figure out how to do it. I can validate on update using this in the model: def validate if self.bartypes.count > 4 errors.add_to_base("Please only select 4 Bar types") end if self.restauranttypes.count > 4 errors.add_to_base("Please only select 4 Restaurant types") end end That works great after the record is created but it doesnt work on create because I would guess that there is no way to count the records before they are created. Is there a way to count the params in the model? I could just count the number of records that the form sends. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---