Virtual/Flexible attributes on model

I’ve a requirement to put some user-managed attributes on a model.

Essentially, I want Entity-Attribute-Value functionality - the
administrator has the ability to create “fields” on the model, and to
specify their type (datetime, string, boolean, decimal, etc). Then in
the regular views, those fields are show in addition to all the normal
fields from the model’s table. This could work with a :has_many
relationship; with the parent model having an overloaded “method
missing” call to look for any members of the associated attributes
that match called-for methods.

I could roll-my-own, but thought I’d look at any existing EAV options
first; but have found thin pickings!
There’s a fork of “acts_as_eav_model” on Github [1] which allows for
flexible attributes on models; and to my mind, “all” I need to do to
have this do what I want is have some form of admin system to populate
the :meta_columns hash with the user-declared options.

But can anyone suggest any other options that might be worth
considering?

[1] GitHub - dwg/acts_as_eav_model: Entity-attribute-value model for ActiveRecord

On 3 June 2010 15:06, Michael P. [email protected] wrote:

I could roll-my-own, but thought I’d look at any existing EAV options
first; but have found thin pickings!
There’s a fork of “acts_as_eav_model” on Github [1] which allows for
flexible attributes on models; and to my mind, “all” I need to do to
have this do what I want is have some form of admin system to populate
the :meta_columns hash with the user-declared options.

But can anyone suggest any other options that might be worth considering?

I’d start with the simplest solution:

class UserAccount < ActiveRecord::Base
serialize :meta_data, Hash
end

Then work up from there as you need more functionality…

I’m sure others will recommend larger, more full featured solutions, but
simple serialization may work for you/others reading this thread in the
future.

Cheers,

Andy

agree,
eav, is build based on data serialization

try it, if u will be required more, than simply switching to eav

Ivan N.
[email protected]

On 3 June 2010 15:15, Andy J. [email protected] wrote:

class UserAccount < ActiveRecord::Base
serialize :meta_data, Hash
end

That would get it working to demo, but I know that they’re going to
want to search/filter on the attributes once they have their hands on
them, so I’d prefer to start with a DB record per attribute that gets
assigned.

class UserAccount < ActiveRecord::Base
serialize :meta_data, Hash
end

That would get it working to demo, but I know that they’re going to
want to search/filter on the attributes once they have their hands on
them, so I’d prefer to start with a DB record per attribute that gets
assigned.

Fair enough.

I’ve not needed to do it yet, so I’ll bow out (just thought I’d post the
simple solution in case someone out there finds this thread and didn’t
know
about it).

Good luck chap.

Cheers,

Andy

Michael P. wrote:

On 3 June 2010 15:15, Andy J. [email protected] wrote:

class UserAccount < ActiveRecord::Base
serialize :meta_data, Hash
end

That would get it working to demo, but I know

Really? Or do you guess?

that they’re going to
want to search/filter on the attributes once they have their hands on
them, so I’d prefer to start with a DB record per attribute that gets
assigned.

EAV is generally a bad idea. If serialize won’t work for you, then your
best bet is probably a schemaless non-SQL database such as MongoDB or
TokyoCabinet.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

may be watch to documented db? something like mongodb?

Ivan N.
[email protected]