autotelik / datashift

Full Excel/CSV Import/Export facilities for Rails
http://www.autotelik.co.uk
Other
136 stars 75 forks source link

More Complex Examples #26

Closed pnomolos closed 9 years ago

pnomolos commented 10 years ago

I'm hoping to use this for a project where I have some rather complicated import/export logic, and am wondering if there are any examples of this nature (where you actually extend the generator/importer). If not, would it be possible to create an example, or point me in the right direction and I can maybe write one? :)

Consider the use case of a Post that belongs to many Sub Categories, with each Sub Category belonging to a Parent Category. In my case, the logic is such that a Post must belong to one (and only one) of each Parent Category's Sub Categories. Say that we have a "Department" Parent Category, and a "Project" Parent Category. Each Post must belong to one of "Department"'s Sub Categories, and one of "Project"'s Sub Categories. However, the data is manipulated by humans as part of the import/export process, so I'm hoping to have an excel sheet that looks something like the following:

post_id other_field category:Department:sub_category category:Project:sub_category
1 something Accounting Greenhouse
2 a value Accounting Bridge
3 value 2 Engineering Greenhouse
4 something Engineering Bridge
autotelik commented 10 years ago

https://github.com/autotelik/datashift_spree

this extends datashift to handle Spree e-commerce, Products etc

https://github.com/autotelik/datashift_spree/blob/master/lib/loaders/spree/product_loader.rb

.. includes procssing specific headers to manage some complex associations

I had started to look at embedding the data for associations inside columns, as a hash. but this very much WIP .. see

https://github.com/autotelik/datashift/blob/master/lib/exporters/csv_exporter.rb

    def record_to_column(record)

This would maybe give something like

category Department { subcategory => Accounting } Department { subcategory => Engineering }

that was just a working idea, specifics of the syntax etc still open for debate

autotelik commented 9 years ago

Closing as this work on roadmap - You can currently do something like category:name:Department:sub_category

This will find a Category where :name => "Department" - and also store the 'sub_category' portion in a data blob called header_default_data - which you could access in your custom loader to do whatever necessary

Also looking at supporting JSON in association rows. Currently completed for export - dumps out the associations attributes as a json blob