8000 GitHub - hayesdavis/active-expando: 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.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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.

Notifications You must be signed in to change notification settings

hayesdavis/active-expando

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

active-expando

Hayes Davis

hayes [at] appozite [dot] com

What?

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.

Why?

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.

Usage

Basic Example

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'})

Using Delegate

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'})

Installation

Install as a rails plugin

script/plugin install git://github.com/hayesdavis/active-expando.git

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0