Giter Site home page Giter Site logo

Comments (7)

mfunaro avatar mfunaro commented on September 8, 2024

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.

from garner.

dblock avatar dblock commented on September 8, 2024

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

from garner.

fancyremarker avatar fancyremarker commented on September 8, 2024

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 ActiveRecord::Base.proxy_binding as the Mongoid mixin does. For Mongoid, this looks like:

# 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

from garner.

mfunaro avatar mfunaro commented on September 8, 2024

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 Patient.identify(params[:id])

from garner.

dblock avatar dblock commented on September 8, 2024

Looking forward to some pull requests!

from garner.

danielkummer avatar danielkummer commented on September 8, 2024

👍 on this...

from garner.

ericgross avatar ericgross commented on September 8, 2024

Would love to see a PR for this 👍

from garner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.