Package to convert BelongsTo subqueries into one query with left join