1. 25 1月, 2015 4 次提交
    • S
      Expand the number of types which can use prepared statements · 3327cd3f
      Sean Griffin 提交于
      This will allow all types which require no additional handling to use
      prepared statements. Specifically, this will allow for `true`, `false`,
      `Date`, `Time`, and any custom PG type to use prepared statements. This
      also revealed another source of nil columns in bind params, and an
      inconsistency in their use.
      
      The specific inconsistency comes from a nested query coming from a
      through association, where one of the inversed associations is not
      bi-directional.
      
      The stop-gap is to simply construct the column at the site it is being
      used. This should simply go away on its own once we use `Attribute` to
      represent them instead, since we already have all of the information we
      need.
      3327cd3f
    • S
      Don't mutate `where_values` · ae8cd56c
      Sean Griffin 提交于
      This is to help facilitate future refactorings, as the internal
      representation is changed. I'm planning on having `where_values` return
      an array that's computed on call, which means that mutation will have no
      affect. This is the only remaining place that was mutating (tested by
      replacing the method with calling `dup`)
      ae8cd56c
    • S
      Don't rely on relation mutability when building through associations · c80487eb
      Sean Griffin 提交于
      Specifically, the issue is relying on `where_unscoping` mutating the
      where values. It does not, however, mutate the bind values, which could
      cause an error under certain circumstances. This was not exposed by the
      tests, since the only place which would have been affected is unscoping
      a boolean, which doesn't go through prepared statements. I had a hard
      time getting better test coverage to demonstrate the issue.
      
      This in turn, caused `merge` to go through proper logic, and try to
      clear out the binds associated with the unscoped relation, which then
      exposed a source of `nil` for the columns, as binds weren't expanding
      `{ "posts.id" => 1 }` to `{ "posts" => { "id" => 1 } }`. This has been
      fixed.
      
      The bulk of `create_binds` needed to be moved to a separate method,
      since the dot notation should not be expanded recursively.
      
      I'm pretty sure this removes a subtle quirk that a ton of code in
      `Relation::Merger` is working around, and I suspect that code can be
      greatly simplified. However, unraveling that rats nest is no small task.
      c80487eb
    • S
      4c0a9922
  2. 24 1月, 2015 1 次提交
  3. 20 1月, 2015 4 次提交
    • S
      Fix bind value copying from subqueried relations · 04d1c371
      Sean Griffin 提交于
      With the old implementation, the bind values were created, and then we
      search the attributes for `Relation` objects, and merge them. This
      completely ignores the order that the actual `where` clause will use. If
      all non-relation where parameters are before the relations, it will
      work. However, if we query on both a relation and a value, with the
      value coming second, it breaks. The order of the hash should not affect
      the final query (especially since hashes being ordered is an
      implementation detail)
      04d1c371
    • S
      Move `create_binds` over to the `PredicateBuilder` · 50a8cdf0
      Sean Griffin 提交于
      I'm looking to introduce a `WhereClause` class to handle most of this
      logic, and this method will eventually move over to there. However, this
      intermediate refactoring should make that easier to do.
      50a8cdf0
    • S
      Whether a column exists or not doesn't affect whether we can use binds · 40887135
      Sean Griffin 提交于
      Looking through the blame, this logic used to be when we actually
      created the bind tuple. My guess is that `nil` couldn't be handled there
      at that time. It can, now.
      40887135
    • S
      Don't mutate bind values in `Relation` · 76d7d957
      Sean Griffin 提交于
      In order to better facilitate refactoring, most places that mutated
      `bind_values` have already been removed. One last spot snuck through.
      Since we're no longer mutating the array, it also does not need to be
      duped in `initialize_copy`.
      76d7d957
  4. 10 1月, 2015 1 次提交
    • S
      Properly copy nested bind values from subqueried relations · ec475547
      Sean Griffin 提交于
      This is cropping up all over the place. After a brief dive, I'm really
      not sure why we have `arel.bind_values` at all. A cursory grep didn't
      reveal where they're actually being assigned (it's definitely in AR, not
      in Arel). I'd like to dig further into it, as I'm fairly certain we
      don't actually need it, we just need a way for the predicate builder to
      communicate merged binds upstream.
      
      Fixes #18414
      ec475547
  5. 06 1月, 2015 1 次提交
  6. 05 1月, 2015 1 次提交
  7. 04 1月, 2015 2 次提交
  8. 02 1月, 2015 1 次提交
  9. 30 12月, 2014 2 次提交
    • S
      Remove all cases of manuallly wrapping `Arel::Nodes::Quoted` · f916aa24
      Sean Griffin 提交于
      This is no longer required now that we are injecting a type caster
      object into the Arel table, with the exception of uniqueness
      validations. Since it calls `ConnectionAdapter#type_cast`, the value has
      already been cast for the database. We don't want Arel to attempt to
      cast it further, so we need to continue wrapping it in a quoted node.
      This can potentially go away when this validator is refactored to make
      better use of `where` or the predicate builder.
      f916aa24
    • S
      Rely on the injectable type caster for `arel_table` · 7eed50c7
      Sean Griffin 提交于
      This API will require much less consuming code to change to accomodate
      the removal of automatic type casting from Arel. As long as the
      predicates are constructed using the `arel_table` off of an AR subclass,
      there will be no changes that need to happen.
      7eed50c7
  10. 27 12月, 2014 13 次提交
    • S
      Inform Arel we don't need additional type casting in batches · 108df8cc
      Sean Griffin 提交于
      Part of the larger refactoring to remove type casting from Arel. We can
      inform it that we already have the right type by wrapping the value in
      an `Arel::Nodes::Quoted`. This commit can be reverted when we have
      removed type casting from Arel in Rail 5.1
      108df8cc
    • S
      Inform Arel that we don't need additional type casting in batching · 50d7e448
      Sean Griffin 提交于
      Part of the larger refactoring to remove type casting from Arel. We can
      inform it that we already have the right type by wrapping the value in
      an `Arel::Nodes::Quoted`. This commit can be reverted when we have
      removed type casting from Arel in Rail 5.1
      50d7e448
    • S
      Go through normal where logic in `apply_join_dependency` · 3eb16cea
      Sean Griffin 提交于
      Part of the larger refactoring to remove type casting from Arel.
      3eb16cea
    • S
      We don't need to type cast the offset in `find_in_batches` · b4e6e474
      Sean Griffin 提交于
      Part of the larger refactoring to remove type casting from Arel. We can
      inform it that we already have the right type by wrapping the value in
      an `Arel::Nodes::Quoted`. This commit can be reverted when we have
      removed type casting from Arel in Rail 5.1
      b4e6e474
    • S
      Eagerly cast array values passed to the predicate builder · 6d4a19cd
      Sean Griffin 提交于
      Part of a larger refactoring to remove type casting from Arel.
      
      /cc @mrgilman
      
      [Sean Griffin & Melanie Gilman]
      6d4a19cd
    • S
      Eagerly cast range values in the predicate builder · eac4658b
      Sean Griffin 提交于
      A custom object is required for this, as you cannot build a range
      object out of `Arel::Nodes::Quoted` objects. Depends on the changes
      introduced in
      https://github.com/rails/arel/commit/cf03bd45e39def057a2f63e42a3391b7d750dece
      
      /cc @mrgilman
      eac4658b
    • S
      Perform casting of single values within the predicate builder · 3179b4a8
      Sean Griffin 提交于
      As part of the larger refactoring to remove type casting from Arel, we
      need to do the casting of values eagerly. The predicate builder is the
      closest place that knows about the Active Record class, and can
      therefore have the type information.
      
      /cc @mrgilman
      
      [Sean Griffin & Melanie Gilman]
      3179b4a8
    • S
      Remove `klass` and `arel_table` as a dependency of `PredicateBuilder` · a60770d3
      Sean Griffin 提交于
      This class cares far too much about the internals of other parts of
      Active Record. This is an attempt to break out a meaningful object which
      represents the needs of the predicate builder. I'm not fully satisfied
      with the name, but the general concept is an object which represents a
      table, the associations to/from that table, and the types associated
      with it. Many of these exist at the `ActiveRecord::Base` class level,
      not as properties of the table itself, hence the need for another
      object. Currently it provides these by holding a reference to the class,
      but that will likely change in the future. This allows the predicate
      builder to remain wholy concerned with building predicates.
      
      /cc @mrgilman
      a60770d3
    • S
      Refactor association handling in `PredicateBuilder` · 3bbe88ec
      Sean Griffin 提交于
      I'm attempting to remove `klass` as a dependency of the predicate
      builder, in favor of an object that better represents what we're using
      it for. The only part of this which doesn't fit nicely into that picture
      is the check for an association being polymorphic. Since I'm not yet
      sure what that is going to look like, I've moved this logic into another
      class in an attempt to separate things that will change from things that
      won't.
      3bbe88ec
    • S
      Re-use the predicate builder in the `ArrayHandler` · 392a453b
      Sean Griffin 提交于
      This reduces the number of places which will need to care about single
      value or range specific logic as we introduce type casting. The array
      handler is only responsible for producing `in` statements.
      
      /cc @mrgilman
      
      [Sean Griffin & Melanie Gilman]
      392a453b
    • S
      Change `PredicateBuilder` handler methods to instance methods · a3936bbe
      Sean Griffin 提交于
      This will allow us to pass the predicate builder into the constructor of
      these handlers. The procs had to be changed to objects, because the
      `PredicateBuilder` needs to be marshalable. If we ever decide to make
      `register_handler` part of the public API, we should come up with a
      better solution which allows procs.
      
      /cc @mrgilman
      
      [Sean Griffin & Melanie Gilman]
      a3936bbe
    • S
      Add missing `:nodoc:` · af55197d
      Sean Griffin 提交于
      We're accidentally documenting `PredicateBuilder` and `ArrayHandler`
      since there's a constant which is missing `# :nodoc:`
      af55197d
    • S
      Inject the `PredicateBuilder` into the `Relation` instance · 1d6bb776
      Sean Griffin 提交于
      Construction of relations can be a hotspot, we don't want to create one
      of these in the constructor. This also allows us to do more expensive
      things in the predicate builder's constructor, since it's created once
      per AR::Base subclass
      1d6bb776
  11. 19 12月, 2014 1 次提交
    • M
      Clarity start parameter · d557f1ba
      Michael Dawson 提交于
      I find that `Specifies the starting point for the batch processing.`
      does not give enough information for me to understand what this
      parameter actually does.
      d557f1ba
  12. 11 12月, 2014 1 次提交
  13. 05 12月, 2014 2 次提交
  14. 04 12月, 2014 1 次提交
  15. 03 12月, 2014 2 次提交
  16. 02 12月, 2014 1 次提交
  17. 30 11月, 2014 2 次提交
    • S
      Update Arel usage for rails/arel#98fc2599 · a975407a
      Sean Griffin 提交于
      `where_sql` now requires that we pass it an engine. None of the manager
      classes take an engine in their constructor.
      a975407a
    • S
      Stop using `Arel::Table.engine` · de239066
      Sean Griffin 提交于
      We never actually make use of it on the table, since we're constructing
      the select manager manually. It looks like if we ever actually were
      grabbing it from the table, we're grossly misusing it since it's meant
      to vary by AR class.
      
      Its existence on `Arel::Table` appears to be purely for convenience
      methods that are never used outside of tests. However, in production
      code it just complicates construction of the tables on the rails side,
      and the plan is to remove it from `Arel::Table` entirely. I'm not
      convinced it needs to live on `SelectManager`, etc either.
      de239066