vendredi 6 octobre 2017

removing duplicate entry for csv import in ruby

while importing csv row i need to check wether this is duplicate entry or new entry. my csv looks like this,

         company,location,region,service,price,duration,disabled
         Google,Berlin,EU,Design with HTML/CSS,120,30,false
         Google,San Francisco,US,Design with HTML/CSS,120,30,false
         Google,San Francisco,US,Restful API design,1500,120,false
         Apple,London,EU,Design with HTML/CSS,120,30,false
         Google,Berlin,EU,Design with HTML/CSS,120,30,false
         Apple,Berlin,EU,Restful API design,1500,120,false

Also the row value should be imported in different table whose association is like this

A Company:

  • can have multiple regions: US, EU and each region multiple branches, i.e. London, Berlin. Define a hierarchy to represent this logic.
  • has many Services. If there are more branches, they will all share the same services
  • can be disabled

A Service:

  • has a duration
  • has a price
  • can be disabled
  • if the company is disabled, all services are disabled.

for which i have implemented association like this

       class Company < ApplicationRecord
         has_many :regions
         has_many :services
         has_many :locations, through: :regions
       end

        class Region < ApplicationRecord
         belongs_to :company
           has_many :locations
        end

        class Location < ApplicationRecord
          belongs_to :region
          belongs_to :company
        end

        class Service < ApplicationRecord
          belongs_to :company
         end

How will I import this?

Aucun commentaire:

Enregistrer un commentaire