Neat trick!  I think I'll employ that to shorten some of the
ridiculously long field names I'm dealing with in my project.

-- hijack thread alert --

I'm curious about potentially overriding the triple underscore and
double-underscore aliasing to use dot notation.  I swear half my
debugging time is spent catching where I got the wrong number of
underscores in there to get the right aliases and they are hard to
spot without firing off a SQL output and pasting into SQL Admin
console to get a more meaningful syntax error message, esp. with SQL
Server via ODBC where everything gets surrounded by brackets.

Instead of :transaction_classes___tc, do something that's more
juxtaposed, like :transaction_classes.tc

I would be perfectly happy then typing :code.rpc, :name.rpc, etc. in
order to continue the pattern (and so that the Symbol class could be
extended to support this) vs. remembering to alias table identifiers
with three underscored suffix and prefixing column names with double
underscored table alias.

DB[:billing_details___bd].
  join(:patients___p, :p__chart_number => :bd__chart)
  join(:transaction_classes___tc, :tc__transaction_code =>
:bd__transaction_code).
  join_table(:left, :billing_statuses___bs, :bs__billing => :bd__billing).
  select{[:bd__billing,
      :bs__balance.as(:balance_last_month),
      sum([['C', :extended]].case(0, :transaction_class)).as(:charges),
      sum([['A', :extended]].case(0, :transaction_class)).as(:adjustments),
      sum([['P', :extended]].case(0, :transaction_class)).as(:payments),
      sum(:extended).as(:balance_this_month)]}.
  filter(:bd__entry_date >= start_date).filter(:bd__entry_date <= end_date).
  group(:bd__billing)

DB[:billing_details.bd].
  join(:patients.p, :chart_number.p => :chart.bd)
  join(:transaction_classes.tc, :transaction_code.tc => :transaction_code.bd).
  join_table(:left, :billing_statuses.bs, :billing.bs => :billing.bs).
  select{[:billing.bs,
      :balance.bs.as(:balance_last_month),
      sum([['C', :extended]].case(0, :transaction_class)).as(:charges),
      sum([['A', :extended]].case(0, :transaction_class)).as(:adjustments),
      sum([['P', :extended]].case(0, :transaction_class)).as(:payments),
      sum(:extended).as(:balance_this_month)]}.
  filter(:entry_date.bd >= start_date).filter(:entry_date.bd <= end_date).
  group(:billing.bd)

Of course, I realize the one complication that arises is with
identifiers with spaces and hyphens, but that would probably just be

:'transaction codes'.tc as opposed to all within the string of
:'transaction codes.tc'

Michael
-- 
http://codeconnoisseur.org

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to