When you add a JOIN you should change it to use sql_build_query so the query is ensured to be build correctly