How can I limit the amount of child records that a parent record can have?
A lot of the existing answers (for example: Limit number of objects in has_many association) seem to not consider potential race conditions (such as hurikhan77's answer) and try to implement the check in application-level code via a validation.
Would a table-level lock (EXCLUSIVE) be the correct solution or am I overlooking something?