Code Monkey home page Code Monkey logo

Comments (3)

kirpen avatar kirpen commented on May 17, 2024

Offered wrap it in your gem.
For example, you can add an option to update the model for the column in which the values ​​are unique, and the parameter to check for the existence of pass through getter method in class import.

class EmployeeImporter < ActiveImporter::Base
imports Employee

column 'First name', :first_name
column 'Last name', :last_name
column 'Department', :department do |department_name|
Department.find_by(name: department_name)
end

transfer params to block check_update

check_update 'First name'
end

in the file ' active_importer / lib / active_importer / base.rb'

def check_update(check_column = false)
if check_column
# start find model by unique column
# if model exists, then start update_attributes
end
end
if you tell me how to write an update attributes, I wrap everything and do commit

from active_importer.

kirpen avatar kirpen commented on May 17, 2024

I try like this code, but it is not best way, can you help write best?

on :row_processing do
p = Product.find_by_handle(row['handle'])
attrs = {}
attrs = { handle: row['handle'], title: row['title'], ............. next params ........... }
unless p.nil?
p.update_attributes attrs
skip_rows_if { true }
end
end

This code work, but this is bullshit :(

from active_importer.

kirpen avatar kirpen commented on May 17, 2024

sorry, i find answer in wiki :)
https://github.com/continuum/active_importer/wiki/Update-instead-of-create

from active_importer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.