code: function buildWhereRelationVia (name, value, relation) {
      // get relation model
      var relationModel = relation.model
      // create alias for relation table to use in query
      var relationAlias = this.newAlias(relationModel.name)
      // get via model
      var viaModel = relation.viaModel
      // create alias for via table to use in query
      var viaAlias = this.newAlias(viaModel.name)
      // join model table to via table
      this.join.push( this.joinSql(viaModel.name, viaAlias, relation.viaModelIdColumn, this.alias, relation.modelIdColumn) )
      // get param name
      var paramName = this.newParam(relation.viaRelationIdColumn)
      // get placeholder
      var placeholder = this.unhexId(`:${paramName}`)
      // build sql
      var whereSql = `${viaAlias}.${this.quoteName(relation.viaRelationIdColumn)} = ${placeholder}`
      // add value to params
      this.params[paramName] = value[relation.viaRelationIdColumn]
      // add where clause to query
      this.where.push(whereSql)
      // if via model does not support delete then skip
      if (!defined(viaModel.columns.d)) {
          return
      }
      // get id column names for via table
      var viaIdColumn = viaModel.defaultColumnsInverse.id
      var viaParentIdColumn = viaModel.defaultColumnsInverse.parentId
      // create new alias for joining revisions
      var viaRevisionAlias = this.newAlias(viaModel.name)
      // join viaModel on self to get current revision
      this.join.push( this.leftJoinSql(viaModel.name, viaRevisionAlias, viaParentIdColumn, viaAlias, viaIdColumn) )
      // add where clause to skip old revisions
      this.where.push(`${viaRevisionAlias}.${this.quoteName(viaIdColumn)} IS NULL`)
      // add where clause to skip deleted records
      this.where.push(`${viaAlias}.d = 0`)
  }
docs: @function buildWhereRelationVia
  
  build where clause for related model that is reference via another model
  
  @param {string} name
  @param {array|boolean|object|string} value
  @param {object} relation
  
  @throws {Error}