ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Fix nested conditions, polymorphic associations handling

Open bopm opened this issue 11 months ago • 0 comments

Fix nested conditions, polymorphic associations handling

This PR addresses several issues with Ransack's handling of polymorphic associations and negative predicates:

Key Improvements

  1. Polymorphic Association Support: Added proper handling for polymorphic associations in correlated subqueries by correctly managing both foreign key and type columns.

  2. Negative Predicate Handling: Fixed the behavior of negative predicates (not_null, not_cont, etc.) when used with associations:

    • not_null: true/false now generates the correct IN/NOT IN queries
    • not_cont now properly generates NOT IN queries with LIKE conditions
  3. Complex AND Conditions: Improved extraction of correlated keys from complex AND conditions with multiple children.

  4. String Wildcard Handling: Added proper quoting for string values containing wildcards (%) in LIKE predicates.

  5. Nested Condition Detection: Added helper method to correctly identify nested vs. non-nested conditions.

Tests Added

  • Tests for wildcard string handling in LIKE/NOT LIKE predicates
  • Tests for negative conditions on associations
  • Tests for nested condition identification
  • Comprehensive tests for polymorphic associations with not_in predicate
  • Tests for complex AND conditions with multiple children

Other Changes

  • Removed pending status from a previously failing test that now passes
  • Added .idea to .gitignore

This PR fixes issues with complex queries involving polymorphic associations and negative predicates, which previously generated incorrect SQL.

This PR incorporates changes from #1537 and #1279.

bopm avatar May 21 '25 23:05 bopm