Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Delegate to visit instead of calling .id directly #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bollard
Copy link

@bollard bollard commented Oct 30, 2014

This is related to #348

Translation of an ActiveRecord::Base object to an integer should be defined once (i.e. in visit_ActiveRecord_base). This makes it easier for the case when a user does not want to query by id but some other field, for example persistent_id

This is related to activerecord-hackery#348

Translation of an ActiveRecord::Base object to an integer should be defined once (i.e. in visit_ActiveRecord_base). This makes it easier for the case when a user does not want to query by `id` but some other field, for example `persistent_id`
@ernie
Copy link
Contributor

ernie commented Oct 30, 2014

👎 on this. AR maps Base#id to whatever the primary key is.

@bollard
Copy link
Author

bollard commented Oct 30, 2014

And AR can still can continue to map Base#id to whatever it wants...

  def visit_ActiveRecord_Base(o, parent)
    if some_condition
      o.id # Call Base#id and retrieve primary key
    else
      # some thing else
    end
  end

But at the Squeel level I would hope this could be configurable.

Squeel is a useful abstraction away from Arel / AR which has allowed us to monkey patch bi-temporal support into Rails (for which this PR helps me continue to use). I very much hope this level of abstraction can be maintained to help support plugin developers

@ernie
Copy link
Contributor

ernie commented Oct 30, 2014

Monkey patching Squeel which monkey patches ActiveRecord which monkey patches everything hardly seems like a sustainable path forward for your app/library.

@bollard
Copy link
Author

bollard commented Oct 30, 2014

I agree it is certainly not an ideal situation to be in, however when making such invasive changes to Rails we were always going to have to patch a number of places in the internals.

This proposed patch is quite the opposite though - a small innocuous change which will have no noticeable impact to almost all of your users, but be incredibly useful to a small number of them and arguably make the internal API more consistent 😄

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

Successfully merging this pull request may close these issues.

2 participants