keithlayne / awesome_sausage

Making Arel sausage.
MIT License
1 stars 0 forks source link

Arel attribute aliases #1

Open wycleffsean opened 9 years ago

wycleffsean commented 9 years ago

Consider overloading bracket operator for retrieving arel attributes like in https://github.com/camertron/arel-helpers

Foo[:id]
Foo[:name]
# instead of
Foo.id
Foo.name_column

avoids the *_column naming foolery

keithlayne commented 8 years ago

I just saw this. I don't like the brackets. I don't like the symbols, because they are strings. You can get that whole thing by delegating brackets to Foo.arel_table.

I was thinking that it would be better to maybe attach a submodule where all this stuff could live to each AR class. Then you could reference it explicitly, or maybe even a query builder method that passes the stuff you want, like:

# A, B, C ... are classes derived from AR::Base

complex_arel = with_tables(A, B, C) do |a, b, c|
  # a is a ref A::Table or something
  # ... some thing where you can use a.name, etc. with no name conflicts
end

Then you can be explicit, get the sugar, and avoid monkey-patching. You could use it pretty flexibly then.