D
D
dexdev2015-01-25 18:00:08
MySQL
dexdev, 2015-01-25 18:00:08

How to import data from .xlsx to mysql join table using rails?

There is a label Items
structure
id | category_id | name | description | price | wall_th | size |
Items have links

has_many :item_gosts
has_many :gosts, through: :item_gosts
has_many :item_steel_marks
has_many :steel_marks, through: :item_steel_marks

linked tables item_gosts and item_steel_marks
and there is a .xlsx file
Name Size, mm GOST, OST, TU Steel grade Description Price/ton
Cold-rolled seamless pipe 45x4 8734; 8732 3sp; 20; 10 GOST 8734, steel 3sp, 10, 20, L = 5-10.5 257664
Which corresponds to the structure of the plate Items
id | category_id | name | description | price | wall_th | size |
1 | 26 | Seamless cold-rolled pipe | L = 5-10.5 | 257664 | 4 |45 |
and for join tables item_gosts
8734; 8732 two of them get
item_steel_marks 3sp
; 20; 10 these three things
are easy to insert into the Item table, it’s clear how
and how to insert tables into join is not clear!!
Help someone thread.
10,000 entries, 4 hours sitting only about 400 manually made

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2015-01-25
@DmitriyEntelis

In 4 hours, you can throw an ineffective but obvious script on the forehead: if some value points to another table, we look for it there, if not, we insert it. One way or another, we get the id of the record and paste it where necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question