Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myabc/325137 to your computer and use it in GitHub Desktop.
Save myabc/325137 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'mysql://root:@localhost/test')
DataMapper.setup(:logs, "sqlite3:///tmp/test.db")
class LoggedEvent
include DataMapper::Resource
def self.default_repository_name; :logs; end
property :id, Serial
property :action, String
belongs_to :user
end
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :logged_events, :repository => :logs
end
DataMapper.auto_migrate!
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'])
/Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/associations/relationship.rb:211:in `parent_model': Cannot find the parent_model User for LoggedEvent in user (NameError)
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/associations/relationship.rb:237:in `parent_key'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/associations/many_to_one.rb:45:in `child_key'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model.rb:708:in `assert_valid'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model.rb:707:in `each_value'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model.rb:707:in `assert_valid'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model.rb:706:in `each_value'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model.rb:706:in `assert_valid'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:1310:in `auto_migrate!'
from dm-repository-issue.rb:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment