« Previous
Ohm gotchas
Published on 20/01/12
by andrewhao
Here’s a list of things that have been annoying, or at least a bit frustrating using Ohm, the Redis ORM, in a Rails app. Beware to those who assume Ohm is ActiveRecord in new clothes. It is, but it’s not:
CRUD
Don’t make the mistake of treating your Ohm objects like AR:
| ActiveRecord | Ohm |
|---|---|
destroy |
delete |
self.find(id) |
self[id] |
update_attributes |
update |
create |
create |
Also note that Ohm’s update_attributes behaves differently from Rails` — it doesn’t persist the updates to DB. That owned me for the good part of the day.
Callbacks
Thankfully, these are ActiveRecord-like with the addition of ohm/contrib.
Associations
| ActiveRecord | Ohm |
|---|---|
has_a or belongs_to |
reference |
has_many |
collection |
Read this article if you’re considering creating associations from AR objects to Ohm objects and the other way ‘round.
That's it. What Next?
Please leave your comment so we know what you think about this article. Trackback URL: Ohm gotchas.
Leave a Reply