database code taken inside model