Wednesday, April 28, 2010

[Rails] Re: adding custom fields dynamically to a model

pankaj wrote:
> I have a model called List which has many records
>
> class List
>
> has_many :records
>
> end
>
> class Record
>
> end
>
> The table Record has 2 permanent fields: name, email. Besides these 2
> fields, for each List a Record can have 'n' custom fields.
>
> for example: for list1 I add address(text), dob(date) as custom
> fields. then while adding records to list one, each record can have
> values for address and dob.
>
> Is there any activerecord plugin which provides this type of
> functionality. Else could you share your thoughts on how to model
> this.

If there's really no common schema beyond name and e-mail, then you have
several options to play with:

* Use a serialized hash for the "extra" fields.
* Put the "extra" fields in some other table and use associations.
* Use a schemaless database such as MongoDB.

This is not something that SQL databases do easily.

>
> Thanks in advance, Pankaj

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate