update select query generator to handle nested belongsTo