Hi Marco,
The MiniZinc compiler currently does not have the capability to do this type of partial flattening. With a focus on incremental compilation for MiniZinc, it’s certainly something that we might be interested in for the future, but not something that will be available any time soon.
Note that depending on your model and purpose, the flattening time might not be prohibitive. I have used MiniZinc in the application of large neighbourhood search, where each neighbourhood was flattened separately and found that the resulting performance was often fit for purpose.
Otherwise, I have seen an application that “templated” the FlatZinc. The idea is to compile one instance of the model, then trace the input data that can change into the FlatZinc, and exchange this for a templating variable for a templating library. Note that this generally only works if the “amount” of objects in the data (that results in different constraints) does not change, and if it is easy to trace the FlatZinc back to the MiniZinc.