Acts_as_tree and :include

hello there,
i have a model that uses acts_as_tree:

class GbEntry < ActiveRecord::Base
acts_as_tree :order => ‘created_at DESC’
end

and i want it to paginate, including all children to avoid unnecessary
db queries:

@gb_entry_pages, @gb_entries =
paginate :gb_entries, :per_page => 15, :order => ‘created_at DESC’, :include => :children

when i run that, i get the followin error:

ActiveRecord::StatementInvalid (Mysql::Error: #23000Column
‘created_at’ in order clause is ambiguous: SELECT gb_entries.id AS
t0_r0, gb_entries.name AS t0_r1, gb_entries.email AS t0_r2,
gb_entries.homepage AS t0_r3, gb_entries.message AS t0_r4,
gb_entries.created_at AS t0_r5, gb_entries.parent_id AS t0_r6,
childrens_gb_entries.id AS t1_r0, childrens_gb_entries.name AS
t1_r1, childrens_gb_entries.email AS t1_r2,
childrens_gb_entries.homepage AS t1_r3,
childrens_gb_entries.message AS t1_r4,
childrens_gb_entries.created_at AS t1_r5,
childrens_gb_entries.parent_id AS t1_r6 FROM gb_entries LEFT OUTER
JOIN gb_entries childrens_gb_entries ON childrens_gb_entries.parent_id
= gb_entries.id WHERE gb_entries.id IN (‘30’, ‘29’, ‘28’, ‘27’, ‘26’,
‘25’, ‘24’, ‘23’, ‘22’, ‘21’, ‘20’, ‘18’, ‘17’, ‘16’, ‘15’) ORDER BY
created_at DESC ):

when i remove the include statement, everything works just well. does
anybody know how to adress this problem?

greets


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium

@gb_entry_pages, @gb_entries =
paginate :gb_entries, :per_page => 15, :order => ‘created_at DESC’, :include => :children

change ‘created_at DESC’ to ‘table_name.created_at DESC’. The problem
is that both tables have a created_at column so MySQL doesn’t know
which to use so you need to specify.

when i run that, i get the followin error:

ActiveRecord::StatementInvalid (Mysql::Error: #23000Column
‘created_at’ in order clause is ambiguous:

You’ll see this error a lot when doing joins unless you make a habit
of calling all columns by their table_name.column_name form.

Cheers,
Chuck V.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs