-
Notifications
You must be signed in to change notification settings - Fork 86
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
Broken queries when used in conjunction with friendly_id and globalize #27
Comments
Seems related to the same issue encountered by @kidlab in #9. My first guess is that something is going awry in I haven't fully made sense of the code yet, but my general impression is that the keys that should get prefixed don't get separated correctly from those that should remain instead unprefixed (lines 6 to 8). EDIT Thus maybe it should become from: opts, acts_as_opts = opts.stringify_keys.partition { |k,v| attribute_method?(k) } to something along the lines of: opts, acts_as_opts = opts.stringify_keys.partition { |k,v| attribute_method?(k) or reflections.has_key?(k) } |
UPDATE: I've made a couple of tests in my code, didn't have time to make a full PR. opts, acts_as_opts = opts.stringify_keys.partition { |k,v| attribute_method?(k) or k.include?(".")} The matter seems to be that {"collection_translations.slug"=>"autumn-winter"}
{"boxes"=>{"collection_translations.slug"=>"autumn-winter"}} |
Just to further expand on this answer as I was having a similar issue with querying on associations in general (although I don't use the "." notation for my where clauses). I think it would be better if this statement was checking attribute_method? on the acting_as_model instance, not the specific instance. Like so:
|
I'll close this for now. Please reopen (https://github.com/krautcomputing/active_record-acts_as/issues) if this is still an issue with the current version. |
When using
acts_as
in conjunction withfriendly_id
andglobalize
, the finders on the model get broken due to an incorrect WHERE condition injected in the query (parent_model.child_model_translations.slug = ?
where it should have beenchild_model_translations.slug = ?
).Models:
My
schema.rb
(relevant portions):Gem versions (from
bundle show
)Exception raised when invoking, e.g.,
Collection.friendly.find('autumn-winter')
orCollection.find_by_slug('autumn-winter')
:Full query that triggered the exception:
What the query looks like without
acts_as
:The text was updated successfully, but these errors were encountered: