Browse files

Show how to create the first resource

  • Loading branch information...
1 parent f8ce5b5 commit 6a4df2cf45b904b3d483ea6984cea7e3e6a5ae7c @namelessjon namelessjon committed Apr 26, 2010
Showing with 27 additions and 0 deletions.
  1. +27 −0 getting-started.markdown
@@ -185,4 +185,31 @@ add columns to existing tables. It won't change any existing columns though
(say, to add a NOT NULL constraint) and it doesn't drop any columns. Both these commands
also can be used on an individual model (e.g. `Post.auto_migrate!`)
+Create your first resource
+Using DataMapper to [create](/docs/create_and_destroy#creating)) a resource (A
+resource is an instance of a model) is simple
+{% highlight ruby %}
+# create makes the resource immediately
+@post = Post.create(
+ :title => "My first DataMapper post",
+ :body => "A lot of text ...",
+ :created_at =>
+# Or new gives you it back unsaved, for more operations
+@post = => ..., ...) # persist the resource
+{% endhighlight %}
+Both are equivalent. The first thing to notice is we didn't specify the
+auto-increment key. This is because the data-store will provide that value for
+us, and should make sure it's unique, too. Also, note that while the property
+is a `DateTime`, we can pass it a `Time` instance, and it will convert (or
+typecast) the value for us, before it saves it to the data-store. Any
+properties which are not specified in the hash will take their default values in
+the data-store.

0 comments on commit 6a4df2c

Please sign in to comment.