Traffic flow prediction is a crucial task in enabling efficient intelligent transportation systems and smart cities. Although there has been rapid progress in this area in the last few years, given the major advances of deep learning techniques, it remains a challenging task because of the inherent periodic characteristics of traffic flow sequence. To incorporate the periodicity in the prediction process, existing methods have observed three components separately as the input of prediction models, i.e., the closeness, period, and trend components. The long term relation of these components has not been fully addressed. In this paper, we present a novel architecture, TRAILER (TRAnsformer-based tIme-wise Long tErm Relation modeling), to predict traffic flows more effectively. First, we explicitly design a Transformer based long term relation prediction module to model the long term relation and predict the periodic relation to be used for the downstream task. Second, we propose a consistency module at the target time interval, in order to model the consistency of the predicted periodic relation and the relation inferred from the predicted traffic flow tensor. Finally, based on the consistency module, we introduce a consistency loss to stabilize the training process and further improve the prediction performance. Through extensive experiments, we show the superiority of the proposed method on three real-world datasets and the effectiveness of each module in TRAILER.