Is there a way to create a generated column that contains a count of related objects?

Desired behavior:

Say you have a table Parents that contains a 1:N relation to a table Children.

Is there a way to have a generated column on table Parents that states the Count of related Children and that updates automatically when additional relations are added?

There is the Count function in SQL but I am not sure how to make it work with relations.

1 Like

Hello @Andreas_Marinopoulos

Unfortunately only columns from table, to which generated column is added, can be used in generated column expressions. If you want to generate value basing on columns from other tables, you must do it in your code.

Regards,
Inna