Created
March 3, 2010 11:11
-
-
Save solnic/320537 to your computer and use it in GitHub Desktop.
This code uses dm-core from snusnu's active_support branch and dm-mongo-adapter from master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
DataMapper.setup(:default, "mysql://localhost/examples") | |
DataMapper.setup(:logs, "mongo://localhost/examples") | |
class LoggedEvent | |
include DataMapper::Mongo::Resource | |
def self.default_repository_name; :logs; end | |
property :id, ObjectID | |
property :action, String | |
belongs_to :user | |
all.destroy! | |
end | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :logged_events, :repository => :logs | |
auto_migrate! | |
end | |
user = User.create(:name => 'jola') | |
user.logged_events.create(:action => 'bazinga!') | |
user.logged_events.create(:action => 'foo') | |
user.logged_events.create(:action => 'bar') | |
puts '-' * 80 | |
p user.logged_events(:action => /foo|bar/) | |
p LoggedEvent.all(:user => user, :action => ['bazinga!', 'foo']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------- | |
[#<LoggedEvent @id="4b8e441825de443108000002" @action="foo" @user_id=1>, #<LoggedEvent @id="4b8e441825de443108000003" @action="bar" @user_id=1>] | |
[#<LoggedEvent @id="4b8e441825de443108000001" @action="bazinga!" @user_id=1>, #<LoggedEvent @id="4b8e441825de443108000002" @action="foo" @user_id=1>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment