Has_many relationships and minimums

New to Rails and the list.

Quick questions regarding has_many relationships that require at least 1

I’m aware of validate_size_of and use this to make sure that the parent
is not saved without at least one child. Question is, is there some
Rails magic to help when removing children to ensure the last one is not
removed? Currently I’m calling something like this in my controller:

unless parent.children.size == 1

Is there a more ‘Rails’ way to do this?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs