Ruby on Rails Wednesday, July 1, 2015

On 1 July 2015 at 16:51, John Lahr <johnelahr@gmail.com> wrote:
> Can you limit the number of related records a given parent record has?
>
> Example. Class/Student relatoinship. A Class has_many students but I want
> to limit the size of a class to a max 30 (of course minimum or exact numbers
> would hopefully work the same way?)

There may be a better way but I would just use a validation that
prevents further students being added to the class when the limit is
released.

By the way, can a student be in more than one class? If so then you
need has and belongs to many or (which I prefer) has many through.

Colin

>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/aadce5fd-8e2a-4596-9b68-b88c952354a2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu3J0a8d0p8dEsmcmaQYwPMYZaMu%2BQ2wCCG3A8iOzbehw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment