parsePivot(models) {
      return _.map(models, (model) => {
        // Separate pivot attributes.
        const grouped = _.reduce(
          model.attributes,
          (acc, value, key) => {
            if (hasPivotPrefix(key)) {
              acc.pivot[removePivotPrefix(key)] = value;
            } else {
              acc.model[key] = value;
            }
            return acc;
          },
          {model: {}, pivot: {}}
        );

        // Assign non-pivot attributes to model.
        model.attributes = grouped.model;

        // If there are any pivot attributes create a new pivot model with these attributes.
        if (!_.isEmpty(grouped.pivot)) {
          const Through = this.throughTarget;
          const tableName = this.joinTable();
          model.pivot = Through != null ? new Through(grouped.pivot) : new this.Model(grouped.pivot, {tableName});
        }

        return model;
      });
    }
Creates new pivot models in case any of the models being processed have pivot attributes.
This is only true for models belonging to {@link Model#belongsToMany belongsToMany} and
{@link Model#through through} relations. All other models will discard any existing pivot
attributes if present.

@param {Model[]} models List of models being processed.
@return {Model[]} Parsed model list possibly containing additional pivot models.