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

Rails 7 + multiple databases with Active Record is failing coz of this gem #195

Closed
kapso opened this issue Feb 13, 2022 · 1 comment
Closed

Comments

@kapso
Copy link

kapso commented Feb 13, 2022

Steps to reproduce

class ApplicationRecord < ActiveRecord::Base
  primary_abstract_class
end
class ReadReplicaRecord < ApplicationRecord
  self.abstract_class = true
  connects_to database: { writing: :primary, reading: :primary_replica }
end
class User < ReadReplicaRecord
end

database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  username: db_user
  password:

development:
  primary:
    <<: *default
    url: postgres://db_user:@localhost:5432/db_name
  primary_replica:
    <<: *default
    url: postgres://db_user:@localhost:5432/db_name

The following fails, (if you remove the ros-apartment gem, it will work)

ReadReplicaRecord.connected_to(role: :reading) do
  User.count
end

Additional NOTES

Expected behavior (without ros-apartment gem)

Loading development environment (Rails 7.0.2.2)
irb(main):001:1* ReadReplicaRecord.connected_to(role: :reading) do
irb(main):002:1*   User.count
irb(main):003:0> end
  User Count (1.0ms)  SELECT COUNT(*) FROM "users"
=> 80    

Actual behavior (with ros-apartment gem)

irb(main):001:1* ReadReplicaRecord.connected_to(role: :reading) do
irb(main):002:1*   User.count
irb(main):003:0> end
/Users/kapil/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activerecord-7.0.2.2/lib/active_record/connection_handling.rb:137:in `connected_to': unknown keyword: :database (ArgumentError)  

System configuration

Rails 7.0.2.2
Ruby 3.1.0
ros-apartment 2.11.0
PostgreSQL 14.1

@lunks
Copy link
Contributor

lunks commented Feb 13, 2022

Duplicate of #193 even though this has a better issue description, it's the same issue.

Related #194

@lunks lunks closed this as completed Feb 13, 2022
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

2 participants