ranked-model icon indicating copy to clipboard operation
ranked-model copied to clipboard

allow writing with_same in string

Open gagalago opened this issue 9 years ago • 6 comments

now we can do:

ranks :row_order,
        with_same: 'service_id IN (SELECT id FROM services WHERE agency_id = #{instance.agency_id})'

has_one :agency, through: :service
  delegate :id, :name, to: :agency, prefix: true

fix issue #89

gagalago avatar Apr 29 '15 14:04 gagalago

this would be great to allow ranking through associations!

julianrubisch avatar Mar 22 '22 11:03 julianrubisch

Perhaps there's a cleaner way to do this?

brendon avatar Mar 22 '22 21:03 brendon

Sorry, by cleaner, I mean safer.

brendon avatar Mar 22 '22 21:03 brendon

Yep, I was thinking the same - then again, I don't know how user input should make it into a class method 😬 , but you never know.

Totally spitballing, but what if instead of evaling a string, you could pass a lambda to with_same? That would (probably?) allow joining your association together until you arrive at the necessary key?

julianrubisch avatar Mar 23 '22 07:03 julianrubisch

I will let anyone of you takeover of this pull request. I don't have time anymore to handle it and I don't use this gem anymore neither.

gagalago avatar Mar 23 '22 08:03 gagalago

All good @gagalago.

Yes @julianrubisch, perhaps something like a proc or lambda that exposes the current scope as self so that it can be further refined?

brendon avatar Mar 23 '22 21:03 brendon