Simple trick to work with ActiveRecord dynamic column and encapsulated accessor

Just writing this so i can remind if i need it again 🙂 I’m in the middle of creating a generic flexible domain modeling module (i call it flexi-model).

In brief flexi-model is schema less flexible modeling tool. It can store your data of any kinda it does trick just providing generic value method and pick up the right column type from preset column definition from model class.

Just to make it easier to grasp here is a sample code –

I’ve the following structure in –

[Collection - for dynamic schema] -< [Record] -< [Value]

On the form I’m using f.datetime_select :value where (f denotes fields_for of Value instance)
after submission rails was trying to figure out what is :value column in table definition.
since it’s not an existing column so rails was throwing up MultiparameterAssignmentErrors error.

Just after digging bit deep it looks like read_value_from_parameters is responsible for loading real column definition.
So to mock it i’ve added the following code and it works –

thants all 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

my tweets

June 2012
S S M T W T F
« Aug   Jul »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Flickr Photos

RSS my shared links on google reader

  • An error has occurred; the feed is probably down. Try again later.
%d bloggers like this: