Ask coding questions

← Back to all posts
1
read from file and store into database
deeptishukla24 (2)

Hello,

I'm trying to read a json file and store it into the database.
This file has more than 1000 records. I have included a sample in the file.json file in my linked repl. The actual file is hosted on S3.

So, in my app, I have created four models - User, Info, City, Dept.
The relationship is:

  • user has_one :info
  • info has_one :city and also has_one :dept

However, when I'm trying to save it to database, I'm getting this error:

#<ActiveRecord::AssociationTypeMismatch: Info(#70231905516980) expected, got {:first_name=>"first1", :last_name=>"last1", :dept_id=>11, :city_id=>58, :dept=>{:id=>11, :title=>"Logistics"}, :city=>{:id=>58, :title=>"Chicago"}} which is an instance of Hash(#70231909512820)>

Could you please assist me in finding what I'm missing here?