Closed Looooong closed 5 years ago
I wasn't aware of this use case for attribute
(having a database column, but overriding the serializer). It might be possible to only do include ActiveType::NestedAttributes
instead of inheriting from ActiveType::Record
, in order to get nests_many
, but not the new behaviour of attribute
. I have not tested that, though.
I could see three ways to address this
include ActiveType::NestedAttributes
, so users can get nests_many
without attribute
.attribute
method. This is a big breaking change. I'm a bit hesitant to do this for a use case I never had.attribute
method as ar_attribute
or something. This is kind of unexpected, but might fix the use case above.@triskweline Any thoughts?
@kratob Can we support custom serializers in our attribute
?
I'm using Rails 4.2.8
@kratob I tested include ActiveType::NestedAttributes
and it doesn't work :(
@triskweline Having custom serializer for your attribute
is a good idea. I'd like to also have an ability to persist defined attribute
to a database column (just assign attribute and let Rails handles the abstraction?).
I can look into supporting custom serializers. It would probably require a significant rewrite though, since our attribute
is not designed to do any serialization at all.
OK, so unless someone wants to attempt a PR with tests, I don't see us implementing this any time soon.
Just so this doesn't trip up people in the future, how about we expose the original method as ar_attribute
as @kratob suggested. When someone passes a non-symbol type to our attribute
we could raise an error with instructions to use ar_attribute
instead.
Sounds good to me. Be aware, in Rails 5, we can use both symbol and type object for custom type, reference.
ActiveRecord.attribute
is now exposed as .ar_attribute
. Unfortunately I cannot print any warnings, since an ActiveModel::Type
is valid for the second arguments to ActiveType.attribute
, it just does not work to override behavior for database-backed columns.
(Released as 1.1.0).
I want to have custom serialization for my column type in Postgres, so I do this
However, if I switch to
ActiveType::Record
,::attribute
behaves differently and doesn't serialize the column. I think the::atttribute
methods fromActiveRecord::Base
andActiveType::Record
must be differentiate from each other and the later must not override the former with different behaviour.Also, I would love to see that
nests_many
work in conjunction with custom column serializer in this example: