-
Notifications
You must be signed in to change notification settings - Fork 24
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
Does Garner support binding ActiveRecord models? #84
Comments
After some more spelunking through the code, I see that my use case is not implemented yet. No need to look into this for me. I'm going to see if I can replicate some of the Mongoid features in ActiveRecord. |
Would be really happy to see complete ActiveRecord support! Currently we say: Garner provides rudimentary support for ActiveRecord. To use ActiveRecord models for Garner bindings, use Garner::Mixins::ActiveRecord::Base. You can set it up in an initializer: require "garner/mixins/active_record"
module ActiveRecord
class Base
include Garner::Mixins::ActiveRecord::Base
end
end |
Hey @mfunaro, I'm using Garner w/ ActiveRecord, but can confirm that binding to classes won't work out of the box (just instances). In order to bind to classes, the ActiveRecord mixin would need to implement # Only find the latest if we can order by :updated_at
return nil unless fields['updated_at']
only(:_id, :_type, :updated_at).order_by(updated_at: :desc).first It'd be similar for ActiveRecord. Something like this would work (though it's not optimized): return nil unless columns.map(&:name).include?('updated_at')
order('updated_at DESC').first |
Thanks for the responses. @fancyremarker, I did end up doing something very similar to what you suggested to get things working in a fork. I also created an identity for ActiveRecord so that I could use |
Looking forward to some pull requests! |
👍 on this... |
Would love to see a PR for this 👍 |
Just getting started with Garner and I am having trouble binding to ActiveRecord models. I debugged down into the code and it seems that if you bind an ActiveRecord model class such as
garner.bind(Patient) ... end
, by default the SafeCacheKey strategy will be used, but since the model class wont respond to :cache_key or :updated_at, we return from the apply method of the strategy with no binding_keys which effectively skips the cache.Am I doing something wrong? I tried figure out what to do with ActiveRecord from the Mongoid samples.
Any help would be greatly appreciated, also sorry if this is not the correct place for questions, I looked for a Google Group and didn't find one.
The text was updated successfully, but these errors were encountered: