ActiveModel::Attributes (array: true) - should it require Postgres?

Hi,

I’m really enjoying using the new ActiveModel::Attributes API for making form objects (replacing Virtus).

At the moment, if you want to do :

class Foo
include ActiveModel::Model
include ActiveModel::Attributes

attribute :bars, :string, array: true

``

you must be using the postgresql adapter and further, it seems you can only do this on a “real” schema backed model (i.e. the above won’t work, even if you were using postgres)

I’m wondering if this is likely to change (i.e. if there’ll be a feature for non-database backed models that you’ll be able to use these “ActiveRecord::Type modifiers” on ActiveModels as well. Seems to me that it should be possible to make it so that it’s not coupled to a particular database schema. That said, I find this all quite tricky stuff so I’m almost certainly missing something :wink:

Thanks,

Patrick

ActiveModel is agnostic to the database, you can use it without using any database, so no, it should not require Postgres.

I believe
array: true

``

on an ActiveRecord model, with MySQL, or SQLite, is possible too.

Just combine it with “serialize”

https://apidock.com/rails/ActiveRecord/Base/serialize/class

Sorry wrong reference
You should look at

https://apidock.com/rails/ActiveRecord/AttributeMethods/Serialization/ClassMethods/serialize

instead.

Thanks for the reply San Ji :slight_smile:

ActiveModel is database agnostic, however, the attribute :foo, :my_custom_type, array: true syntax from the new activerecord::attributes api is only available to postgres, as it’s defined on the postgres adapter

Possibly my question should be put to the core-team mailing list, as, really I’m wondering about whether the feature should be built in.