Skip to content

Instantly share code, notes, and snippets.

@solnic
Created August 30, 2010 13:48
Show Gist options
  • Select an option

  • Save solnic/557430 to your computer and use it in GitHub Desktop.

Select an option

Save solnic/557430 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'dm-core'
require 'dm-mysql-adapter'
require 'dm-migrations'
require 'dm-validations'
DataMapper.setup :default, "mysql://localhost/tests"
module DM
class Group
include DataMapper::Resource
storage_names[:default] = "groups"
property :id, Serial
property :name, String
has n, :students
end
class Student
include DataMapper::Resource
storage_names[:default] = "students"
property :id, Serial
property :name, String
belongs_to :group
end
end
DataMapper.auto_migrate!
ActiveRecord::Base.establish_connection :adapter => "mysql", :database => "tests"
module AR
class Group < ActiveRecord::Base
set_table_name "groups"
has_many :students
end
class Student < ActiveRecord::Base
set_table_name "students"
belongs_to :group
end
end
ar_student = AR::Student.create :group_id => 'foo'
dm_student = DM::Student.create :group_id => 'foo'
puts "ar_student errors: #{ar_student.errors.inspect}" # => {}
puts "dm_student errors: #{dm_student.errors.inspect}" # => #<DataMapper::Validations::ValidationErrors:0x8df30d8 @resource=#<DM::Student @id=nil @name=nil @group_id="foo">, @errors={:group_id=>["Group must be an integer"]}>
@ku1ik
Copy link
Copy Markdown

ku1ik commented Aug 30, 2010

True dat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment