# Acts\_as\_hash

**URL:** <https://www.ruby-forum.com/t/acts-as-hash/76779>\
**Category:** Rails\
**Created:** [November 29, 2005, 4:46am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779 "2005-11-29T04:46:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [November 29, 2005, 4:46am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779/1 "2005-11-29T04:46:27Z")

</div>

Anyone work on, or interested in, a acts\_as\_hash?

It would allow things like

product.properties[‘isbn’] = 32232323  
product.properties[‘color’] = ‘blue’  
product.save  
id = product.id

…

p = Product.find(id)  
p[‘color’] #=\> ‘blue’

…

Product.hashfind\_by\_properties(‘isbn’, 32232323) #=\> p

It’s useful when the properties you need to store are always changing,  
so you can’t use field mapping, but you want to query by them, and so  
can’t use serializable.

Comments? Suggestions? Criticisms?

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [November 29, 2005, 5:26am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779/2 "2005-11-29T05:26:03Z")

</div>

I think this already exists as :serialize

Or at least, it works for my purposes.

–

On 11/28/05, List R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> can’t use serializable.

## – Garrick Van Buren

## removed\_email\_address@domain.invalid ph: 612 325 9110

First Crack Podcast  
[http://firstcrackpodcast.com/](http://firstcrackpodcast.com/)

gFeed - all my writing in one place

> **[gFeed Now More Valid](https://garrickvanburen.com/gfeed-now-more-valid/)**
>
> If your news reader didn’t like the gFeed – I’m looking at you, NewsFire – then give it a second shot. I’ve tweaked the gFeed RSS feed and it should be more compatible…

PodcastMN - The Sound of Minnesota  
[http://podcastmn.com/](http://podcastmn.com/)

Garrick’s Podcast Picks

> **[Garrick's Podcast Picks](http://gigadial.com/public/station/9454)**
>
> GigaDial.net is a new approach to radio programming. You can use it to create and subscribe to podcast-powered stations composed of individual episodes from our favorite podcasters.

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [November 29, 2005, 5:51am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779/3 "2005-11-29T05:51:21Z")

</div>

garrick.vanburen wrote:

> I think this already exists as :serialize

You can’t do SQL queries by fields of :serialize . You need to  
instantiate all the objects into Ruby, and check them one by one, which  
is slow (although it can be done in one line of code).

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [November 29, 2005, 7:11am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779/4 "2005-11-29T07:11:12Z")

</div>

I’ve jsut made a blog post on a quick-and-dirty way to do the querying  
using the ‘serialize’ column:

[http://www.karmiccoding.com/articles/2005/11/29/querying-serialized-data-in-activerecord](http://www.karmiccoding.com/articles/2005/11/29/querying-serialized-data-in-activerecord)

Not brilliant, and more or less untested, but better than pulling all  
of the data from the server and parsing it application side. Very  
simple to turn into a plugin, too.

Cheers!

-DF

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [November 29, 2005, 9:28am UTC](https://www.ruby-forum.com/t/acts-as-hash/76779/5 "2005-11-29T09:28:27Z")

</div>

Hi,

As far as I know there is no one working on this but I would love to  
see an addition like this to rails.

On 11/29/05, List R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> can’t use serializable.

–  
Cheers,

Peter D.
