Project template, add custom property

Hello,
I have a question about adding a custom property to project template and how to auto-populate that field in the children projects.

I have made a simple module that stores some name of categories (eg.: “environment”, “audit”, “privacy”, …). This module works fine.

My goal is to include those categories in my project template: I’m gonna do a template for environmental projects for example. In Studio I have created a 1-M relation between this categories module and Project template and Project module. I also add this new field to those modules.

So now I can modify my projects to assign them a categories, and I can modify my Project templates in the same way, but I’m not able to generate a child project from template with the template’s category. When I create a new project from template, the project has that field unset.

I imagine I have to modify the code directly but I don’t find the where in the application flow.

Could you help me?
Thank you.

I’ve found a solution, tell me if it’s the right method.
First I have loaded the relationship between template and categories tables, finding the value I need. After that I’ve loaded relationship with project and categories, setting the value previously saved.

$template->load_relationship(’<categories_template_relationship_link_name>’);
$value = $template->categories_template_relationship_link_name->get();

$project->load_relationship(‘categories_project_relationship_link_name’);
$project->categories_template_relationship_link_name>add($value);