Fix for cases where alias is not a table name: make if clause in get_extra_join_sql more precise. Test added.