Skip to content
Provides a single point of entry for using basic features of ruby ORMs
Failed to load latest commit information.
spec Merge pull request #37 from cheerfulstoic/patch-1 Aug 5, 2014
.gitignore Adds activerecord 4 gemfile, and tells travis to build it with ruby 1… Nov 12, 2013
.rspec Coloured rspec output Jun 12, 2012
Gemfile Found some more Gemfile to lock Jun 6, 2014
History.txt Adds active record 4.1 to the test suite Apr 28, 2014
README.rdoc Remove merge mistake in README Aug 5, 2014
Rakefile Adds activerecord 4 gemfile, and tells travis to build it with ruby 1… Nov 12, 2013
orm_adapter.gemspec Expand Travis matrix by adding JRuby and Rubinius. Minor changes to G… Jan 13, 2014


ORM Adapter Build Status

Provides a single point of entry for popular ruby ORMs. Its target audience is gem authors who want to support more than one ORM.

Example of use

require 'orm_adapter'

User # is it an ActiveRecord, DM Resource, MongoMapper or MongoId Document?

User.to_adapter.find_first :name => 'Fred' # we don't care!

user_model = User.to_adapter
user_model.get!(1)                      # find a record by id
user_model.find_first(:name => 'fred')  # find first fred
user_model.find_first(:level => 'awesome', :id => 23)
                                        # find user 23, only if it's level is awesome
user_model.find_all                     # find all users
user_model.find_all(:name => 'fred')    # find all freds
user_model.find_all(:order => :name)    # find all freds, ordered by name
user_model.create!(:name => 'fred')     # create a fred
user_model.destroy(object)              # destroy the user object

@see OrmAdapter::Base for more details of the supported API

Supported ORMs

Currently supported ORMs are ActiveRecord, DataMapper, MongoMapper, and MongoId.

We welcome you to write new adapters as gems. ORM Adapter will stay focused in having these major ORMs working. Other adapters will be named orm_adapter-somedatabase, you can find the ones available on rubygems.

To write an adapter look at lib/orm_adapter/adapters/active_record.rb for an example of implementation. To see how to test it, look at spec/orm_adapter/example_app_shared.rb, spec/orm_adapter/adapters/active_record_spec.rb. You'll need to require the target ORM in spec/spec_helper.rb


ORM Adapter's goal is to support a minimum API used by most of the plugins that needs agnosticism beyond Active Model.

ORM Adapter will support only basic methods, as get, find_first, create! and so forth. It is not ORM Adapter's goal to support different query constructions, handle table joins, etc.

ORM adapter provides a consistent API for these basic class or 'factory' methods. It does not attempt to unify the behaviour of model instances returned by these methods. This means that unifying the behaviour of methods such as ``, and `model.valid?` is beyond the scope of orm_adapter.

If you need complex queries, we recommend you to subclass ORM Adapters in your plugin and extend it expressing these query conditions as part of your domain logic.


orm_adapter is an extraction from pickle by Ian White. Pickle's orm adapter included work by Daniel Neighman, Josh Bassett, Marc Lee, and Sebastian Zuchmanski.

José Valim suggested the extraction, and worked on the first release with Ian.

Luke Cunningham contributes the Mongo Mapper adapter.

Fred Wu contributes the #destroy methods, and :limit, :offset options for #find_all

Tim Galeckas


To run the specs, you can start from the last known good set of gem dependencies in Gemfile.lock.development:

git clone
cd orm_adapter
bundle install
bundle exec rake spec

To run specs for different versions of ORMs, you can specify a gemfile from the `gemfiles` directory, e.g.

BUNDLE_GEMFILE=gemfiles/activerecord-4.1.gemfile bundle install
BUNDLE_GEMFILE=gemfiles/activerecord-4.1.gemfile bundle exec rake spec


Copyright © 2010-2013 Ian White and José Valim. See LICENSE for details.

Something went wrong with that request. Please try again.