Using macro {{this}} and {{selected_resources}} fail because one is empty at compilation and the other at execution

In this case, you should specify a database in the configuration. You should point out that modelA should be created in project1 and modelB in project2. dbt will handle everything else.