complete sql query for has_one_through method. functionality complete