The menu_link_content
entity definition contains information related to your question; namely, the database table that contain the parent-child relation would be menu_link_content_data
.
Below is a code sample that would deliver an array of node ids given a parent node, provided that there is a menu link attached to the node.
This code uses Drupal's APIs instead of SQL queries.
<?php
// Get the root based on a given node, e.g. node 58.
$menu_link_root_entities = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->loadByProperties([
'link' => [
'uri' => 'entity:node/58'
],
],
);
$menu_link_root = reset($menu_link_root_entities);
// Need to call this in order to instantiate the tree_storage service.
$menu_tree = \Drupal::menuTree();
// Get menu link content entities based on their parent property.
$menu_links = \Drupal::service('menu.tree_storage')->loadByProperties([
// Need a filter value like menu_link_content:8031d182-7a0b-4798-839a-6c66bdd1f27b
'parent' => 'menu_link_content:' . $menu_link_root->uuid(),
]) ?: [];
$node_ids = array_map(function($v){
return $v['route_parameters']['node'];
}, $menu_links);
Hope this helps, good luck!