Created
August 30, 2010 13:48
-
-
Save solnic/557430 to your computer and use it in GitHub Desktop.
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 '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"]}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
True dat.