laravel/laravel — pull request #1030 by douglinsmeyer (2012-07-30 02:33:48+00:00)
Title: Improvement to fluent select

Ability to define Eloquent relationship as such and retain all origin and pivot columns
as well as include explicit calculated columns such as aggregates.

Previous version of this function overwrote query columns array upon sequential select() calls,
this version merges selects into the columns array with priority to existing columns.

public function widgets()
{
return $this->has_many_and_belongs_to('Widget', 'transactions')->group_by('widget_id')->select((array(DB::raw('SUM(quantity) as total'))))->having('total', '>', '0');
}