has_many and has_many_through functionalities of rails is implemented in ruby code