6 ms·
Rails 4.0 Sneak Peek: Expanded ActiveRecord Support for PostgreSQL Datatypes
- emmett 14y agoI want support not just for PostgreSQL native datatypes, I want ActiveRecord support for adding my own custom datatypes.
- jeremymcanally 14y agoYou can pretty much do that right now (and have been able to for years) with composed_of: http://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html http://api.rubyonrails.org/classes/ActiveRecord/Aggregations... (search on that page for it)
- deleted 14y ago[deleted]
- emmett 14y agocomposed_of is the "other half" of what I want. I don't want to use custom ruby classes, I want to use custom Postgresql types. Turns out support for that's in 4.0 too! https://github.com/rails/rails/pull/4775 https://github.com/rails/rails/pull/4775
- joevandyk 14y agoI'm curious to see how it works for types with multiple elements (composite types).
- joevandyk 14y agoThe problem is that custom pg types are represented as strings in ActiveRecord < 4.0. In AR 4.0, you can have ActiveRecord automatically cast them to a different type.
- bcardarella 14y agoType casting is fine but if you need to use schema.rb you'll have to use the sql alternative. Adding explicit support for the existing datatypes allows, amongst other things, the schema.rb
- lobster_johnson 14y agoWe had to abandon schema.rb early because we use PostGIS, functional indexes, partial indexes and foreign key constraints, none of which are supported. (FKs may be supported now, but at the time we had to monkeypatch AR to support it, before eventually abandoning schema.rb altogether.) Schema.rb is inherently a broken concept anyway, because it's lossy. What you really want is the SQL, which is the only format that completely encapsulates your schema in AR. I often wish AR was declarative for that reason. The default Rails tooling for loading and dumping the structure is also completely harebrained (google it and you will get a gazillion hits), so we wrote our own internal gem that does all of it for us, along with overriding db:test:prepare.
- joevandyk 14y agoThat's in ActiveRecord 4.0 as well! https://github.com/rails/rails/pull/4775 https://github.com/rails/rails/pull/4775 Take a look at @tenderlove's comment down below about the actual implementation (as opposed to my crappy one in the issue body).
- tferris 14y agoRails is the new Java.
- dmishe 14y agoYou can say what you want about rails, but i really admire the pace they make progress.