I am doing it this way:
@disabled_options = []
Category.where('ancestry is NULL').each do |cat|
@disabled_options << cat.id if cat.has_children?
end
Is there any more elegant way to get all parent without children?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming
parent_idis a field pointing to the parent category.This will select those categories that are pointed to using “parent_id”, so if there’s a child, the child will have “parent_id” set, therefore the category referenced to by “parent_id” has children.