Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to require activerecord-import? #474

Closed
gerrywastaken opened this issue Nov 9, 2017 · 9 comments
Closed

How to require activerecord-import? #474

gerrywastaken opened this issue Nov 9, 2017 · 9 comments
Labels

Comments

@gerrywastaken
Copy link

When I set require: false in my Gemfile and instead do the following in a script

require 'active_record'
require 'activerecord-import'
require 'activerecord-import/base'
require 'activerecord-import/import'

activerecord-import instead tries to do every insert as a single insert. What am I doing wrong here?

I can see that supports_import? is somehow being set to false and this is why it doesn't work, but I'm not sure why that would be the case.

@gerrywastaken
Copy link
Author

Ok so I have to load activerecord-import before active_record is loaded: https://github.com/zdennis/activerecord-import/blob/master/lib/activerecord-import.rb#L3

I'm wondering if that should be added to the readme? There is discussion of how adapters need to be loaded, but not activerecord-import itself.

@gerrywastaken
Copy link
Author

I wonder if a lot of people require activerecord-import after active record and then just assume it made no difference to their imports or that it's broken. Perhaps there should be some warning when activerecord_import thinks that the connection doesn't "support_import".

@jkowens
Copy link
Collaborator

jkowens commented Nov 9, 2017

@gerrywastaken I'd have to do some reading on ActiveSupport's lazy loading to better understand what is going on.

@amatsuda are you able to provide any insight and/or suggestions?

@jkowens
Copy link
Collaborator

jkowens commented Nov 20, 2017

@gerrywastaken in your script if you just do:

require 'active_record'
require 'activerecord-import'

Does that work?

@jkowens
Copy link
Collaborator

jkowens commented Nov 20, 2017

There is a wiki entry on how to require activerecord-import. I just want to make sure that it is accurate. Hopefully this will end up in the readme one of these days 😜

https://github.com/zdennis/activerecord-import/wiki/Requiring

@jkowens jkowens added the docs label Nov 20, 2017
@jkowens jkowens changed the title Import does not run as a single query How to require activerecord-import? Nov 20, 2017
@jkowens jkowens mentioned this issue Nov 20, 2017
10 tasks
@gerrywastaken
Copy link
Author

Does that work?

Nope, because the onload of active_record would have already been triggered and so this is this never run:
https://github.com/zdennis/activerecord-import/blob/master/lib/activerecord-import.rb#L3

@jkowens

@gerrywastaken
Copy link
Author

it would be better if there was just a call we could make to initialize activerecord-import at any time no matter the load order.

@jkowens
Copy link
Collaborator

jkowens commented Nov 24, 2017

So I did some testing and the following at the beginning of your script should do the trick:

require 'activerecord-import/base'
require 'activerecord-import/active_record/adapters/postgresql_adapter'

I updated the wiki, but I'll see about adding a method to simplify that initialization.

@gerrywastaken
Copy link
Author

gerrywastaken commented Nov 26, 2017

That's pretty helpful, thanks @jkowens!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants