postgresql - Using Heroku, Rails sort is incorrect on updated_at timestamp column -


i have rails 4.0 app using postgresql on heroku. trying display table xlog or transaction log, showing last 5 entries in reverse order updated_at timestamp. works correctly on local system. when push heroku, sorts incorrectly.

i have checked heroku database definitions , column correctly listed timestamp. have cloned heroku code machine , verified same pushed. @ point, don't know why doesn't work on heroku when works locally. , advice appreciated.

fwiw, remote database , local database not have same data.

the code is: (last line of log_sort added act breakpoint still pass correct result.)

  def self.last_objects object, count     logs = xlog.where(object: object).last(count)     log_sort = logs.sort_by{|log| log.updated_at}.reverse     log_sort   end 

during execution breakpoint, can see variables passed:

code

this local result correct sort:

local result

this heroku result incorrect sort:

heroku result

this heroku postgresql table definition updated_at:

postgresql table

edit: view:

<% xlog = xlog_last(car.stock_number, 5) %> ... <% xlog.each |log| %>     <tr>       <td><%= log.associate  %></td>       <td><%= log.proxy      %></td>       <td><%= log.action     %></td>       <td><%= log.status     %></td>       <td><%= log.message    %></td>       <td><%= log.value      %></td>       <td><%= log.updated_at %></td>     </tr> <% end %> 

helper:

  def xlog_last(object, count)     xlog.last_objects object, count   end 

edit: modified sort_by use order method follows. results did not change @ all. same sorting error occurred , exact same data displayed in exact same way:

new code:

def self.last_objects object, count   logs = xlog.where(object: object).order(updated_at: :desc).first(count)    end 

i believe need use order influence actual sql query. right using sort_by sorting data after read in database. order in db based on how inserted , different heroku , local system. when export heroku, , import it, ordering of tables changes too.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -