{"action":"created","issue":{"url":"https://api.github.com/repos/jackc/tod/issues/23","labels_url":"https://api.github.com/repos/jackc/tod/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/jackc/tod/issues/23/comments","events_url":"https://api.github.com/repos/jackc/tod/issues/23/events","html_url":"https://github.com/jackc/tod/issues/23","id":77912277,"number":23,"title":"Does not work for me at least","user":{"login":"kennyeni","id":972669,"avatar_url":"https://avatars.githubusercontent.com/u/972669?v=3","gravatar_id":"","url":"https://api.github.com/users/kennyeni","html_url":"https://github.com/kennyeni","followers_url":"https://api.github.com/users/kennyeni/followers","following_url":"https://api.github.com/users/kennyeni/following{/other_user}","gists_url":"https://api.github.com/users/kennyeni/gists{/gist_id}","starred_url":"https://api.github.com/users/kennyeni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennyeni/subscriptions","organizations_url":"https://api.github.com/users/kennyeni/orgs","repos_url":"https://api.github.com/users/kennyeni/repos","events_url":"https://api.github.com/users/kennyeni/events{/privacy}","received_events_url":"https://api.github.com/users/kennyeni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-19T03:26:38Z","updated_at":"2015-05-20T01:10:14Z","closed_at":null,"body":"I have a model with:\r\n\r\n```ruby\r\ntime_from :time\r\ntime_to :time\r\n```\r\n\r\nWhen saving gives: `TypeError: can't cast Tod::TimeOfDay to time`\r\n\r\nWhich obviously is because of serialization, if I add the lines to my model:\r\n\r\n```ruby\r\nserialize :time_from, Tod::TimeOfDay\r\nserialize :time_to, Tod::TimeOfDay\r\n```\r\n\r\nIt gives the following error:\r\n\r\n```shell\r\nNoMethodError: undefined method `empty?' for 2000-01-01 08:00:00 UTC:Time\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/tod-2.0.1/lib/tod/time_of_day.rb:172:in `load'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/type/serialized.rb:19:in `type_cast_from_database'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/type/mutable.rb:5:in `type_cast_from_user'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute.rb:100:in `type_cast'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute.rb:42:in `original_value'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute.rb:37:in `value'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute.rb:46:in `value_for_database'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:164:in `store_original_raw_attribute'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:93:in `write_attribute'\r\n\tfrom /Users/Kenny/.tokaido/Gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods.rb:50:in `__temp__4796d656f56627f6d6'\r\n```\r\n\r\nwhen trying to save the following object:\r\n\r\n```ruby\r\n{:day=>1, :time_from=>#<Tod::TimeOfDay:0x007f8813639a00 @hour=8, @minute=0, @second=0, @second_of_day=28800>, :time_to=>#<Tod::TimeOfDay:0x007f8813638fd8 @hour=15, @minute=0, @second=0, @second_of_day=54000>, :default_duration=>3600 seconds\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jackc/tod/issues/comments/103710618","html_url":"https://github.com/jackc/tod/issues/23#issuecomment-103710618","issue_url":"https://api.github.com/repos/jackc/tod/issues/23","id":103710618,"user":{"login":"kennyeni","id":972669,"avatar_url":"https://avatars.githubusercontent.com/u/972669?v=3","gravatar_id":"","url":"https://api.github.com/users/kennyeni","html_url":"https://github.com/kennyeni","followers_url":"https://api.github.com/users/kennyeni/followers","following_url":"https://api.github.com/users/kennyeni/following{/other_user}","gists_url":"https://api.github.com/users/kennyeni/gists{/gist_id}","starred_url":"https://api.github.com/users/kennyeni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennyeni/subscriptions","organizations_url":"https://api.github.com/users/kennyeni/orgs","repos_url":"https://api.github.com/users/kennyeni/repos","events_url":"https://api.github.com/users/kennyeni/events{/privacy}","received_events_url":"https://api.github.com/users/kennyeni/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T01:10:14Z","updated_at":"2015-05-20T01:10:14Z","body":"Well, I do have an example but it fails in the very basic ```MODEL.new(time_attr: Tod::TimeOfDay.new(8))``` call when serialization is required to a 'Time' field in the DB.\r\n\r\nHowever, I found a very easy solution to this, just ```require 'tod/core_extensions'``` when using the serialization :)"}}