Hi Anand,
I spoke with one of our developers, who pointed me to a similar function we use in AtoM's code, that we can borrow for what you need:
So, resources, context and breakdown:
We have some basic SQL queries in our documentation
here, which includes how to
back up your database, and how to
access the MySQL command prompt. I STRONGLY recommend you make a backup before attempting to use SQL in a production database - ideally, you would make a backup, load it into a test site, and perform your queries there first! Anyway, see:
We also have Entity Relationship Diagrams of AtoM's data schema on our wiki. Here is the latest:
I've recently given a very brief overview of AtoM's data model in this thread:
For context: AtoM uses a
Nested set model to manage hierarchical relationships in the relatively flat, table-like structure of a SQL database. This means that in the
information_object table, you will find two fields -
lft and
rgt. You can use the object ID to find the description you want (we have example queries on how to get this from either a slug or [if it's unique enough] a title
in the docs here), and then get these values for the target description.
Now, that
first link? It essentially provides us with an equation you can use to get a count of descendant records (i.e. not just immediate children, but all records in the current hierarchy from the starting record down). That equation is:
That is to say, the
rgt value minus the
lft value minus 1, and that total divided by 2, should give you a count of descendant records.
I hope this helps!