Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ActiveRecord should preserve the full precision from the database, you're just not looking at it properly. Use <code>strftime</code> and the <code>%N</code> format to see the fractional seconds. For example, <code>psql</code> says this:</p> <pre><code>=&gt; select created_at from models where id = 1; created_at ---------------------------- 2012-02-07 07:36:20.949641 (1 row) </code></pre> <p>and ActiveRecord says this:</p> <pre><code>&gt; Model.find(1).created_at.strftime('%Y-%m-%d %H:%M:%S.%N') =&gt; "2012-02-07 07:36:20.949641000" </code></pre> <p>So everything is there, you just need to know how to see it.</p> <p>Also note that ActiveRecord will probably give you <code>ActiveSupport::TimeWithZone</code> objects rather than <code>DateTime</code> objects but <code>DateTime</code> preserves everything too:</p> <pre><code>&gt; '2012-12-31T01:01:01.232323+3'.to_datetime.strftime('%Y-%m-%d %H:%M:%S.%N') =&gt; "2012-12-31 01:01:01.232323000" </code></pre> <hr> <p>Have a look at <code>connection_adapters/column.rb</code> in the ActiveRecord source and check what the <code>string_to_time</code> method does. Your string would go down the <code>fallback_string_to_time</code> path and that preserves fractional seconds as near as I can tell. Something strange could be going on elsewhere, I wouldn't be surprised given the strange things I've seen in the Rails source, especially the database side of things. I'd try converting the strings to objects by hand so that ActiveRecord will keeps its hands off them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload