solve activerecord issue by writing sql