• S
    Refactor Active Record to let Arel manage bind params · 213796fb
    Sean Griffin 提交于
    A common source of bugs and code bloat within Active Record has been the
    need for us to maintain the list of bind values separately from the AST
    they're associated with. This makes any sort of AST manipulation
    incredibly difficult, as any time we want to potentially insert or
    remove an AST node, we need to traverse the entire tree to find where
    the associated bind parameters are.
    
    With this change, the bind parameters now live on the AST directly.
    Active Record does not need to know or care about them until the final
    AST traversal for SQL construction. Rather than returning just the SQL,
    the Arel collector will now return both the SQL and the bind parameters.
    At this point the connection adapter will have all the values that it
    had before.
    
    A bit of this code is janky and something I'd like to refactor later. In
    particular, I don't like how we're handling associations in the
    predicate builder, the special casing of `StatementCache::Substitute` in
    `QueryAttribute`, or generally how we're handling bind value replacement
    in the statement cache when prepared statements are disabled.
    
    This also mostly reverts #26378, as it moved all the code into a
    location that I wanted to delete.
    
    /cc @metaskills @yahonda, this change will affect the adapters
    
    Fixes #29766.
    Fixes #29804.
    Fixes #26541.
    Close #28539.
    Close #24769.
    Close #26468.
    Close #26202.
    
    There are probably other issues/PRs that can be closed because of this
    commit, but that's all I could find on the first few pages.
    213796fb
query_attribute.rb 547 字节