Rails 4.0 先睹為快:擴展ActiveRecord支持PostgreSQL的數據類型
本周,我的一個功能請求已經被接受到下一個版本的 Rails 中,這就是增加對 PostgreSQL 數據庫的 MACADDR、INET 和 CIDR 數據類型的支持,也就是說在 Rails 4.0 中你可以使用如下代碼:
create_table :network_types do |t| t.cidr :cidr_address t.inet :ip_address t.macaddr :mac_address end
同時,數據庫模型的生成也支持這三個數據類型,而之前它們都被當成是字符串來處理。
ActiveRecord 將自動的把 INET 和 CIDR 類型轉成 Ruby 的 IPAddr,而 MACADDR 將轉成字符串類型。
This week, I had a pull request accepted into Rails which adds support forPostgreSQL's MACADDR, INET, and CIDR datatypes. In Rails 4.0, the following migration will be supported:
create_table :network_types do |t| t.cidr :cidr_address t.inet :ip_address t.macaddr :mac_address end
Also, the schema dumper supports these types as well (previously they would appear as string
types in the schema.rb file).
ActiveRecord will also cast the values of the INET and CIDR types to Ruby's IPAddr, while MACADDR will continue to be converted to a string.
via dockyard
本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!