ruby on rails - Save loop of xml to database table -
please see below xml file:
<event id="12987613" link="https://www.skiddle.com/whats-on/bolton/bolton-arena/dldk---dont-let-daddy-know/12987613/?sktag=xxx"> <name><![cdata[dldk - don't let daddy know]]></name> <date>2017-10-07</date> <eventcode>club</eventcode> <shortdesc><![cdata[don't let daddy know returns greater manchester october biggest ever uk show! featuring steve angello, knife party, blasterjaxx]]></shortdesc> <doorsopen>21:00</doorsopen> <doorsclose>06:00</doorsclose> <image>https://d31fr2pwly4c4s.cloudfront.net/9/f/f/962862_3_dont-let-daddy-know_th.jpg</image> <venue id="3764"> <name><![cdata[bolton arena]]></name> <address>bolton arena, arena approach, horwich</address> <city>bolton</city> <town>bolton</town> <citycode>bl6</citycode> <postcode>bl6 6lb</postcode> </venue> <tickets> <ticket id="351828"> <name><![cdata[vip ticket]]></name> <facevalue>50.00</facevalue> <bookingfee>6.00</bookingfee> <quantity>more 10 available</quantity> <status statuscode="1">available</status> </ticket> <ticket id="357740"> <name><![cdata[vip upgrade ticket]]></name> <facevalue>17.50</facevalue> <bookingfee>2.10</bookingfee> <quantity>more 10 available</quantity> <status statuscode="1">available</status> </ticket> </tickets> </event>
i have file filled on 1000 events. i'm wanting potentially pretty easy. i'm making new database table called skiddle_tickets. each ticket belong event. i'm right in thinking in need belongs in model , has many in events model.
what i'm wanting each ticket match event id. tickets placed event table when event created. way works event created via rake task. using same xml file. can capture event id when created.
so want each ticket saved against in table against event if called event.tickets.each can each ticket (or similar)
how go doing this? difficult part xml database part
at moment i'm putting data in database this:
event = { 'custom_event_id' => node['id'], 'eventname' => children.css('name').first.inner_text, } event.create(event)
any ideas, thoughts or suggestions amazing!
Comments
Post a Comment