Dynamically adding constraints with @constraintref

Dear all,

I am trying to dynamically add constraints to my model as in the example below. However, this formulation results in the error stated below the formulation. I believe that the problem occurs due to the [t in t_a] in the @constraint command. Does anyone have an idea how this can be solved?

Z = @variable(m, [t in ts, cg in cgs, lt in lts2], Bin)
@constraintref limit_activation2[cgs, lts2]
for cg in cgs
for lt in lts2
t_a = [t for t in ts if t < L[t][cg][lt][“t_k”]]

           limit_activation2[cg,lt] = @constraint(m, [t in t_a], Z[t,cg,lt] == 0 )


Error: MethodError: Cannot convert an object of type JuMP.JuMPArray{JuMP.ConstraintRef,
1,Tuple{Array{Int64,1}}} to an object of type JuMP.ConstraintRef
This may have arisen from a call to the constructor JuMP.ConstraintRef(…),
since type constructors fall back to convert methods.

@constraintref creates a container for holding ConstraintRef elements but there the elements have type JuMP.JuMPArray{JuMP.ConstraintRef, 1,Tuple{Array{Int64,1}}}.
The easiest way to solve this would be to do

limit_activation2 = Dict{Tuple{eltype(cgs), eltype(lts2)},  JuMP.JuMPArray{JuMP.ConstraintRef,
for ...
    limite_activation[(cg, lt)] = ...

If you prefer using an array instead of a dictionary, you can use AxisArrays