Fixed how select statement fields and conditions are built for related fields