-
Notifications
You must be signed in to change notification settings - Fork 21.9k
ActionCable Postgres adapter is ActiveRecord-specific #27214
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
Comments
That is a good point. I don't see why this code is using Active Record at all, it should not, even more that actioncable doesn't depend on activerecord and active record base is not being required in that file. In my opinion we should use the pg connection directly. |
@rafaelfranca my guess is it's because it's piggybacking on the AR database config logic. An alternative approach to supporting any ORM is to have a config setting that lets me specify how to get a new PG connection, defaulting to the AR method used currently. I did notice the lack of a require at the top which is maybe a separate but related issue? |
I prefer to use the connection directly over supporting different ORM. There is no need for a ORM in actioncable. We can't add the require without changing the dependencies of actioncable to add activerecord, so I prefer that we solve this issue removing any orm specific code. |
Thank you for opening up this issue! Working on a solution locally now. |
Opened up #27216 as a possible solution for this. |
This issue remains open after... 6 years! RailsGuides still mention this behavior might be changed |
I would like to use it together with MongoID. I have already a MongoDB cluster on production and I would like to avoid adding Redis, because of different reasons. |
I've released a rubygem which enhances the Postgres adapter, making it possible to bypass the ActiveRecord dependency by adding explicit Rubygem: https://rubygems.org/gems/actioncable-enhanced-postgresql-adapter |
I written one that uses mongoid. |
https://gist.github.com/washu/a2b5415e7b9a538fe782d32ff5bb9109 I just wrapped some code i had in my own crystal/anycable type bridge |
Steps to reproduce
Expected behavior
Ideally, this would support the most popular Postgres ORMs out of the box. Or at least the docs should mention that this only works with AR.
Actual behavior
Exception trying to autoload ActiveRecord
System configuration
Rails version: 5.0.0.1
Ruby version: 2.3.3
It was very easy to fork the Postgres ActionCable subscription adapter to work with Sequel. I only had to alter the
with_connection
method, which is even shorter with Sequel: https://gist.github.com/bgentry/5a4592dbbcc398c0ad651c53af7da51f#file-postgresql_sequel-rb-L35-L40I'm not sure whether the right approach is to try to support this out-of-the-box, or at least to document that the adapter is AR-specific. Thoughts?
As a user I'd certainly prefer not to have to maintain a fork of the subscription adapter. But I can certainly see the argument for this not being Rails' problem. I suppose I really only need to monkey-patch or refine that one method, though, so not too bad either way.
The text was updated successfully, but these errors were encountered: