#55

New

Sort Fails with Multiple belongs_to Relationships

Reported by SingleShot on Ajax Scaffold · 03/11/2006 04:27:34

Assigned to:
rrwhite
Priority:
Normal
Status:
New
Category:
None
Version:
3.1.9

When an active record has two belongs_to relationships to the same table, sorting on either column in the view only sorts the first of the two columns, i.e. sorting on the second column actually sorts the first column.

A poorly devised example ActiveRecord:

class Thing < ActiveRecord::Base

belongs_to :left_side, :class_name => “Side”, :foreign_key => “left_side_id” belongs_to :right_side, :class_name => “Side”, :foreign_key => “right_side_id” @scaffold_columns = [ AjaxScaffold::ScaffoldColumn.new(self, { :name => “left_side_id”, :eval => “thing.left_side.name”, :sort_sql => “sides.name” }), AjaxScaffold::ScaffoldColumn.new(self, { :name => “right_side_id”, :eval => “thing.right_side.name”, :sort_sql => “sides.name” }), ]

end

Example paginator:

@paginator, @things = paginate(:things, :order_by => @sort_by, :per_page => default_per_page, :include => [:left_side, :right_side])

Note: the version in this report is actually 3.1.10 (not in the version list).

Attachments Upload

No attachment has been uploaded, yet.


Loading comments...