Skip to content

Conversation

@metaskills
Copy link
Member

Creating or updating records resets the attributes by mapping the hash using ActiveRecord's Attribute#forgetting_assignment method. This method essentiall mimics the reload by setting the attributes to FromDatabase using the FromUser value "for the database".

rails/rails@07723c23

This is a problem for us because the value_for_database for date time objects are strings that can not be re-parsed due to SQL Server's time formats. For example, a date of August 18th 2016 would be formatted as '08-19-2016' and fail deserialize:

ActiveModel::Type::Date.new.deserialize('08-19-2016') # => nil

Both ActiveModel's date and time types rescue Date.parse methods of new_date and new_time with nil. It was suggested that we use Data classes for our time types and we may explore that after this commit which essentially prepends a new forgetting_assignment method that checks the type. If it is a SQL Server date/time, it will just convert that value object to a FromDatabase using the existing value.

cc @sgrif

Creating or updating records resets the attributes by mapping the hash using ActiveRecord's `Attribute#forgetting_assignment` method. This method essentiall mimics the reload by setting the attributes to FromDatabase using the FromUser value "for the database".

rails/rails@07723c23

This is a problem for us because the `value_for_database` for date time objects are strings that can not be re-parsed due to SQL Server's time formats. For example, a date of August 18th 2016 would be formatted as '08-19-2016' and fail deserialize:

``` ruby
ActiveModel::Type::Date.new.deserialize('08-19-2016') # => nil
```

Both ActiveModel's date and time types rescue `Date.parse` methods of `new_date` and `new_time` with nil. It was suggested that we use Data classes for our time types and we may explore that after this commit which essentially prepends a new `forgetting_assignment` method that checks the type. If it is a SQL Server date/time, it will just convert that value object to a FromDatabase using the existing value.

cc @sgrif
@metaskills metaskills merged commit 000b9c7 into master Dec 9, 2016
metaskills added a commit that referenced this pull request Jan 1, 2017
As part of #528, a few errors were introduced. Since we have a `fast_string_to_time` implementation that uses a custom format which includes %N, parsing the time for DB from DB could fail. So we ensure we always have a nanosecond on the SQL even if it is 0. No need not to.
metaskills added a commit that referenced this pull request Jan 1, 2017
As part of #528, a few errors were introduced. Since we have a `fast_string_to_time` implementation that uses a custom format which includes %N, parsing the time for DB from DB could fail. So we ensure we always have a nanosecond on the SQL even if it is 0. No need not to.
@metaskills metaskills deleted the rails5-forgetting_assignment2 branch January 15, 2017 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants