Does an object have children - method

Is there a technique/method that tells whether an object has a child or
many children or no children?

for example

parent has_many :children_1
parent has_many :children_2

Given the parent, how do I get the two collections of children?

in this case parent.children_1 is an array and you can simply use
if parent.children_1 then


parent.children_1.each do |child|


since it’s nil if there are no children

or use:
to get the actual number of children

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