rails/arel — Issue #102: Alias working for where
Author: daniel2d2art
Created: 2012-02-20 23:30:12+00:00
State: open

Setting alias for table:
```
a = Foo.arel_table
a1 = a.alias("#{a.name}_1")
a2 = a.alias("#{a.name}_2")

inner_where = a1[:attr1].eq(a2[:attr1])
```
just working on joins:
```
a.join(a2).on(a1[:attr1].eq(a2[:attr1])).to_sql
```
returns:
```
"SELECT FROM \"foos\"
INNER JOIN \"foos\" \"foos_2\"
ON \"foos\".\"attr1\" = \"foos_2\".\"attr1\""
```
Same approach for nested where, no way:
```
a.where( a.where(inner_where).exists).to_sql
```
Don't express Alias for From clauses
```
"SELECT FROM \"foos\"
WHERE EXISTS (SELECT FROM \"foos\"
WHERE \"foos_1\".\"attr1\" = \"foos_2\".\"attr1\")"
```
Self subqueries needs some like:
```
"SELECT FROM \"foos\" \"foos_1\"
WHERE EXISTS (SELECT FROM \"foos\" \"foos_2\"
WHERE \"foos_1\".\"attr1\" = \"foos_2\".\"attr1\")"
```