Has_many relationships and minimums

Hi,
New to Rails and the list.

Quick questions regarding has_many relationships that require at least 1
child.

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
@parent.children.delete(Child.find(params[:child_id]))

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

Tekin

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