1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

14 commits

Author SHA1 Message Date
Eileen M. Uchitelle
99b607e6ad
Merge pull request #38719 from eileencodes/refactor-fetch_attribute
Refactor fetch_attribute
2020-03-13 16:26:49 -04:00
eileencodes
166aee88e4
Remove convenience class alias
This convenience class is only used twice in Arel. We can easily write
it out instead.
2020-03-13 13:48:08 -04:00
eileencodes
ce7bbc3685
Refactor fetch_attribute
Similar to the work done in #38636, instead of using case statements we
can make these classes respond to `fetch_attribute`.

New classes can implement `fetch_attribute` instead of adding to the
case statement, it's more object oriented, and nicer looking.

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
2020-03-13 13:38:32 -04:00
Yash Ladha
bc95efa7c2
refactor: arel fetch_attribute to get the atrribute node from binary
module.

Reason for doing this change is to pull the node specific changes to
module itself and to not infer on the attributes, rather than assign
responsibility to the member functions to do so.
2020-03-10 15:35:07 +05:30
Ryuta Kamizono
9698c1bff7 Fix unscope when an eq node which has no arel attribute
Current code expect an `eq` node has one arel attribute at least, but an
`eq` node may have no arel attribute (e.g. `Arel.sql("...").eq(...)`).

In that case `unscope` will raise `NoMethodError`:

```
% bundle exec ruby -w -Itest test/cases/relations_test.rb -n test_unscope_with_arel_sql
Using sqlite3
Run options: -n test_unscope_with_arel_sql --seed 4477

# Running:

E

Error:
RelationTest#test_unscope_with_arel_sql:
NoMethodError: undefined method `name' for #<Arel::Nodes::Quoted:0x00007f9938e55960>
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/where_clause.rb:157:in `block (2 levels) in except_predicates'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/arel.rb:57:in `fetch_attribute'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/where_clause.rb:157:in `block in except_predicates'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/where_clause.rb:156:in `reject'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/where_clause.rb:156:in `except_predicates'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/where_clause.rb:31:in `except'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:487:in `block (2 levels) in unscope!'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:481:in `each'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:481:in `block in unscope!'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:471:in `each'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:471:in `unscope!'
    /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:464:in `unscope'
    test/cases/relations_test.rb:2062:in `test_unscope_with_arel_sql'
```

We should check for both `value.left` and `value.right` those are arel
attribute or not.
2020-02-27 18:43:56 +09:00
Gannon McGibbon
12afdba8b9 Fix unscoped grouped where 2019-11-21 17:27:26 -05:00
Josh Goodall
d0e813fc12 Document Arel.sql 2019-09-26 19:37:42 -04:00
Ryuta Kamizono
b57b23a37b Remove unused Arel::Attributes.for
`Arel::Attributes.for` is no longer used since https://github.com/rails/arel/pull/196.
2019-06-15 23:59:41 +09:00
Ryuta Kamizono
49bcb008cb Fix eager loading polymorphic association with mixed table conditions
This fixes a bug that the `foreign_key` and the `foreign_type` are
separated as different table conditions if a polymorphic association has
a scope that joins another tables.
2019-02-18 00:41:43 +09:00
Ryuta Kamizono
862c78b26f Remove unused Arel::Compatibility::Wheres
This class is no longer used since 9cbfc8a370.
2019-01-15 22:13:25 +09:00
Ryuta Kamizono
d0d1cd3d45 Extract Arel.arel_node? helper method 2018-09-28 04:57:12 +09:00
Matthew Draper
354f1c28e8 Arel: :nodoc: all 2018-02-24 18:11:47 +10:30
Matthew Draper
4c0a3d4880 Arel: rubocop -a 2018-02-24 17:16:13 +10:30
Matthew Draper
17ca17072d Merge Arel into Active Record 2018-02-24 17:15:32 +10:30