On Miércoles, 6 de Octubre de 2010 02:58:09 Andrey Voronkov escribió: > Anyway this: > > config.columns[:last_statecustomer_name].includes = > [:customer_programs => :statecustomer] > config.columns[:last_statecustomer_name].sort_by :sql => > 'customer_programs.date DESC'
That line only sets sql to sort all records by last_statecustomer_name, when you click in the column. > > ... > > def last_statecustomer_name > customer_programs.first.try(:statecustomer).try(:name) > end > > not works. It sorts by id. If you want ActiveRecord sort your association when you are using eager loading (find with :include), you can try puttint the order in association definition (customer_programs) or default_scope in CustomerProgram class. If you don't get sql sorting in the eager loading query, you can use sort_by(&:date). The eager loading query is this query: > CustomerProgram Load (0.3ms) SELECT `customer_programs`.* FROM > `customer_programs` WHERE (`customer_programs`.program_id IN > (29,10,12,24,20,15,13,26,11,28,14,16,25,19,30,21,23,32,17,27,18,8,22,9,80,1 >29,1,31,130)) To use sort_by(&:date) change your virtual column like this: def last_statecustomer_name customer_programs.sort_by(&:date).last.statecustomer.try(:name) end > > 2010/10/6 Andrey Voronkov <[email protected]>: > > Please show me whole string of code, where I should use sort_by(&:date) > > > > 2010/10/6 Sergio Cambra .:: entreCables S.L. ::. <[email protected]>: > >> sort_by(&:date) -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.
