Commit Graph

21 Commits

Author SHA1 Message Date
Joe Dupuis
4ab06e21de Fix a code block in the Arel documentation
`+?+` doesn't compile to a code block.
2023-05-06 18:57:12 -07:00
zzak
66246be8c6 Refer to stable guide for ARel security 2023-02-04 09:01:21 +09:00
Matthew Draper
6444ec0d30 Allow Arel.sql to accept bind parameters
Co-authored-by: Ahmed Shahin <codeminator@github.com>
2023-01-29 08:40:30 +10:30
zzak
06d319eb56 Link to security guide on sql inject from Arel.sql 2023-01-14 19:37:35 +09:00
Rafael Mendonça França
21c6c225a3
Merge PR #40491 2021-10-14 20:46:08 +00:00
Jordan Bostrom
18c0c568da docs: use Arel.sql examples that require Arel.sql 2021-08-06 16:58:38 -05:00
Andrey Novikov
a738295805
Arel: Add support for FILTER clause (SQL:2003)
Currently supported by PostgreSQL 9.4+ and SQLite 3.30+

See:

 - http://modern-sql.com/feature/filter
 - https://www.postgresql.org/docs/9.4/static/sql-expressions.html#SYNTAX-AGGREGATES
 - https://sqlite.org/lang_aggfunc.html#aggfilter

Example:

    Model.all.pluck(
      Arel.star.count.as('records_total').to_sql,
      Arel.star.count.filter(Model.arel_table[:some_column].not_eq(nil)).as('records_filtered').to_sql,
    )
2021-07-20 15:17:04 +03:00
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 9cbfc8a370bf6537a02a2f21e7246dc21ba4cf1f.
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