Creating a duplicate record in the related models. In the index action since there is a JOIN of related models. it was creating duplicate entries because of repeated entries in the related model by adding the ids of all the related model records. this solved the problem. Thanks all for your time. Finally, I managed to get it working.