Here''s an ActiveRecord oddity. If I call WebPageCache.create(:key
=>
[1, 2, 3]), AR appears to store a key of [1,2,3].to_yaml even though I
have not specified ''serialize :key''. Is this documented? If
not, it
feels like a bug:
======== schema:
create_table "web_page_caches", :force => true do |t|
t.string "key"
t.binary "value", :limit => 16777215
t.datetime "expiration"
t.datetime "created_at"
t.datetime "updated_at"
end
======== model:
class WebPageCache < ActiveRecord::Base
end
======== results:>> WebPageCache.create(:key=>[1, 2, 3])
=> #<WebPageCache id: 297, key: [1, 2, 3], value: nil, expiration: nil,
created_at: "2010-05-08 03:46:04", updated_at: "2010-05-08
03:46:04">>> WebPageCache.count
=> 1>> WebPageCache.first
=> #<WebPageCache id: 297, key: "--- \n- 1\n- 2\n- 3\n", value:
nil,
expiration: nil, created_at: "2010-05-08 03:46:04", updated_at:
"2010-05-08 03:46:04">
WebPageCache.serialized_attributes
=> {}
=======AR appears to be yaml-fying :key=>[1,2,3] rather than giving a error.
The docs say:
| Active Record can serialize any object in text columns using
| YAML. To do so, you must specify this with a call to the class
| method serialize.
To be pedantic, the docs don''t say what will happen if you
don''t specify
''serialize :key'', but I''d expect an error or
something. I''m writing a
test suite, so it would be handy to test the published behavior.
Any ideas? Pointers?
thanks.
Oh - I almost forgot:
=======bash-3.2$ rails --version ; ruby --version ; mysql --version
Rails 2.3.5
ruby 1.9.1p376 (2009-12-07 revision 26041) [powerpc-darwin9.8.0]
mysql Ver 14.14 Distrib 5.1.36, for apple-darwin9.5.0 (powerpc) using
readline 5.1
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.