On Saturday, June 27, 2015 at 10:37:38 AM UTC-7, Tom Close wrote:
>
> I've come across a strange issue using the timestamps plugin (sequel, ruby
> and postgres versions given at the bottom):
>
> p1 = Scheduling::Period.create(description: "abc", representative_time:
> tt(12,00))
> p2 = Scheduling::Period.first_where(description: "abc",
> representative_time: tt(12,00))
>
> p1 == p1 #=> false
> p1.values == p2.values #=> false
>
> p1.values.each {|k, v| puts "#{k}: #{v == p2[k]}" }
>
> id: true
>
> created_at: true
>
> updated_at: false
>
> description: true
>
> representative_time: true
>
> notification_mode: true
>
> current_state_id: true
>
>
> p1[:updated_at] #=> Sat, 27 Jun 2015 10:13:40 -0700
>
> p2[:updated_at] #=> Sat, 27 Jun 2015 10:13:40 -0700
>
>
> p1[:updated_at].to_f #=> 1435425220.3419495
>
> p2[:updated_at].to_f #=> 1435425220.341949
>
>
> p1.reload == p2 #=> true
>
>
>
> It appears that the database is truncating the timestamp but this
> truncation isn't fed back to the model after creation.
>
>
> Is this a known issue? I'm currently working around it in my tests by
> reloading the model before checking equality. Is there a nicer way of
> getting around the issue?
>
PostgreSQL only stores timestamps in microsecond precision, so it is
expected that there will only be 6 decimal digits for fractional seconds
for timestamps returned from the database. That doesn't fully explain the
behavior you are seeing, since creating a new model object should
automatically refresh the object, unless you are using the
skip_create_refresh plugin.
Any chance you could put together a self contained example showing this
issue? If you can do that, I'll certainly look into it.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.