Commit c8e409c0 by nnnghia98

created data to industry_jobs

parent 56d05385
......@@ -17,8 +17,6 @@ class City < ApplicationRecord
has_many :city_jobs
has_many :jobs, through: :city_jobs
scope :vn_cities, -> {where region: "Việt Nam"} do
where(name: "16") puts "Other"
end
scope :vn_cities, -> {where region: "Việt Nam"}
scope :inter_cities, -> {where region: "#"}
end
......@@ -13,4 +13,6 @@
#
class Industry < ApplicationRecord
has_many :industry_jobs
has_many :jobs, through: :industry_jobs
end
......@@ -33,4 +33,7 @@ class Job < ApplicationRecord
has_many :city_jobs
has_many :cities, through: :city_jobs
has_many :industry_jobs
has_many :industries, through: :industry_jobs
end
......@@ -6,10 +6,13 @@ class JobsImport
job_columns = [:title, :level, :salary, :description, :short_des,
:requirement, :category, :company_id]
city_jobs = []
industry_jobs = []
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
job_csv = JobCsv.new(row)
jobs << job_csv.csv_attributes
city_jobs << [row["company province"], job_csv.title, job_csv.company_id]
industry_jobs << [row["category"], job_csv.title, job_csv.company_id]
end
Job.import job_columns, jobs
......@@ -20,5 +23,13 @@ class JobsImport
city = City.find_by(name: city_name)
job.city_jobs.create(city_id: city.id)
end
puts "Have data in city_jobs table"
industry_jobs.each do |industry_name, job_title, company_id|
job = Job.find_by(title: job_title, company_id: company_id)
industry = Industry.find_by(name: industry_name)
job.industry_jobs.create(industry_id: industry.id)
end
puts "Have data in industry_jobs table"
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment