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

Can't see postgresql tables when using mongoid #159

Open
alfredoreduarte opened this issue Nov 11, 2016 · 0 comments
Open

Can't see postgresql tables when using mongoid #159

alfredoreduarte opened this issue Nov 11, 2016 · 0 comments

Comments

@alfredoreduarte
Copy link

Hi! I'm using mongoid alongside postgresql in a rails 5 app.

My resque jobs work perfectly with the mongoid models, however, whenever I try to use one of my postgresql tables inside a job, I get the following error:

PG::UndefinedTable: ERROR: relation "admins" does not exist LINE 1: SELECT "admins".* FROM "admins" ^ : SELECT "admins".* FROM "admins"

This is my lib/tasks/resque.rake file

require 'resque/tasks'

task "resque:setup" => :environment do
	ENV['QUEUE'] = '*'
	Resque.before_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!
  end

  Resque.after_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.establish_connection
  end
end

The postgres table mentioned does exist, and works perfectly with the rails app. It seems like, at least outside of the main rails app, ActiveRecord defaults to using mongoid, so none of my postgresql models are visible inside the worker.

Am I missing something?

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

No branches or pull requests

1 participant