Open cgriego opened 12 years ago
This would be great, especially when paired with typecasting checks to ensure that associated objects are of the correct class.
Something else that would be extremely awesome (but maybe a bit hard to implement) would be to automatically serialize when an ActiveRecord model declares an association to it.
@Gaelan You should be able to use ActiveRecord's serialized columns/attributes to do this today. I'd be interested in hearing either way if it works or doesn't for you. ActiveAttr may need to become more explicit about its YAML serialization for best results.
class Person
include ActiveAttr::Model
attribute :first_name, :type => String
end
class Post < ActiveRecord::Base
serialize :author
end
Post.new(:author => Person.new(:first_name => "Chris")).save!
@cgriego OK
Models have associations with other models, and attributes don't cover this case very well (especially when initializing a model with a deeply nested hash).