Created
July 19, 2011 16:08
-
-
Save twobitfool/1092916 to your computer and use it in GitHub Desktop.
Revisions
-
twobitfool created this gist
Jul 19, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ class Post include DataMapper::Resource property :id, Serial belongs_to :author, :default => lambda { |r, a| Author.first } end class Author include DataMapper::Resource property :id, Serial property :name, String has n, :posts end bill = Author.create(:name => "Bill") dave = Author.create(:name => "Dave") post = Post.create(:author_id => dave.id) puts post.author.name => "Bill" # default value of author (on post) is beating out the author_id passed in to create