Thomas discusses this in the Secundus Secundae. As he notes here, "among the things that are loved out of charity there has to be an ordering according to their relation to the first principle of this love, i.e., God."