Closed dmitrypol closed 6 years ago
I like the idea of having more escape hatches from the default behavior in the form of hooks.
I'm thinking one hook called import_find_or_create(record)
to customize the find_or_create
behavior. This would allow you to fix your current issue.
https://github.com/stephskardal/rails_admin_import/blob/df0b6429430eafb62e2331d7e6af6751fb33fc19/lib/rails_admin_import/importer.rb#L179
Another hook would be needed to generalize the association fetching (for the multi-tenant account/email case). I'm not sure what that would look like. https://github.com/stephskardal/rails_admin_import/blob/df0b6429430eafb62e2331d7e6af6751fb33fc19/lib/rails_admin_import/import_model.rb#L73
I added additional hooks that would allow implementing better custom logic
I am thinking of before_import_associate and after_import_associate callbacks where developer can do custom pre-processing before associations occur. But I wanted to check in and see if anyone had better ideas?
CSV: amount,user 10,Bob.smith@example.com
But user.email in the DB is bob.smith@example.com so it doesn't find association.
When I do record[:user].downcase in before_import_save it modifies the record, but the association lookup already happened prior to that.