fix the activerecord query issue