Hayes Davis
hayes [at] appozite [dot] com
Attach any attribute to any ActiveRecord object and store it persistently with no schema changes. Retrieve ActiveRecord objects using those properties. Uses MongoDB and MongoMapper. Requires MongoMapper >= 0.7.1.
Lots of (most?) projects have a relational database like MySQL that holds all the core data in that system. If you’ve ever had tables with milions of rows in MySQL you’ll know that schema changes take forever. You’ll also know that you often have to jump through hoops to store non-normalized data in a relational format. However, it’s way too much work to switch an entire system to a non-relational database if you need to flexibly add attributes to some of your ActiveRecord objects or store some de-normalized data easily.
That’s where active-expando comes in. It lets you use yor existing relational ActiveRecord models while giving you the ability to mix in any attributes you want without having to worry about relational structures or long waits for schema changes. And it’s (almost) completely transparent.
user = User.find(1) # Now set an attribute that didn't exist before user.expandos.foreground_color = '000000' # foreground_color is saved in Mongo user.save # Find any users with a black foreground color users = User.expando_find(:all,:conditions=>{:foreground_color=>'000000'})
class Post < ActiveRecord::Base expando_config do delegate :tags end #Other active record stuff end p = Post.find(1) p.tags = ['foo','bar'] #tags is there directly, no need for p.expandos p.save #Find any Post with the tag "foo" Post.expando_find(:all,:conditions=>{'tags'=>'foo'})
Install as a rails plugin
script/plugin install git://github.com/hayesdavis/active-expando.git