Fix crash when deleting an association with composite primary keys#450
Fix crash when deleting an association with composite primary keys#450brendon merged 3 commits intobrendon:masterfrom
Conversation
brendon
left a comment
There was a problem hiding this comment.
Interesting! :) I'm now wondering if this is one I've missed in my other ordering gem:
What do you think?
| foreign_key = caller_class.reflections[name.to_s].foreign_key | ||
| # Handle composite foreign keys (Arrays) by returning as-is | ||
| # Single foreign keys should be converted to symbols | ||
| foreign_key.is_a?(Array) ? foreign_key : foreign_key.to_sym |
There was a problem hiding this comment.
Just wondering here. We convert the columns to symbols for single foreign keys but not for the composite ones? I'm not sure why we do this anyway but maybe those should be converted also?
There was a problem hiding this comment.
Good call. I think we get a symbol back already, but it might be rails version dependent? Good to add for consistency.
|
Yes - it looks like it would also fail in the positioning gem. Also seeing I didn't exclude the test from older version of Rails, so I'll do that. |
|
@brendon do you know if the failing MySQL tests are a known issue? I don't think it's related to my change and I don't have mysql installed locally. |
|
@brendon I'm seeing these same MySQL test failures on the master branch on my laptop. Seems unrelated to my change. Can you confirm if you're seeing this as well? |
|
That's interesting. I'm not seeing any errors with this run: |
|
Seems related to brianmario/mysql2#1414 so I've fixed the version of the gem to Try merging master in and it should all pass :) |
|
Thanks @smathieu, I've released it as |
Problem
acts_as_list fails with NoMethodError: undefined method 'to_sym' for an instance of Array when used with Rails 8.0's composite foreign key feature. This occurs when destroying records through associations with
dependent: :destroy.Why
The
destroyed_via_scope?method inscope_method_definer.rbcalls.to_symondestroyed_by_association.foreign_key, which returns an Array for composite keys in Rails 8.0+.Proposed Solution
Adds support for array in relationships.