Browse files

added docs for the new defineProperties method on models

  • Loading branch information...
1 parent b0d17a9 commit bec0a56b06c484ecc3270bfd08590858fed78c51 Techwraith committed Feb 15, 2012
Showing with 24 additions and 5 deletions.
  1. +11 −0
  2. +13 −5 site/tutorial.html
@@ -250,6 +250,17 @@ Here is an example of a model with some validations:
User = geddy.model.registerModel('User', User);
+Alternatively, you can use the `defineProperties` method to lay out your model:
+ var User = function () {
+ this.defineProperties({
+ login: {type: 'string', required: true}
+ , password: {type: 'string', required: true}
+ , lastName: {type: 'string'}
+ , firstName: {type: 'string'}
+ });
+ }
Creating an instance of one of these models is easy:
var params = {
@@ -277,15 +277,23 @@ <h2 id="models">Creating the Todo model</h2>
- <p>To do this all we have to do is add some <code></code>'s onto the model function:</p>
+ <p>To do this all we have to do is define some properties using the `defineProperties` method:</p>
<pre class="prettyprint">'title', 'string', {required: true});'status', 'string', {required: true});'id', 'string', {required: true});
+var Todo = function () {
+ this.defineProperties({
+ title: {type: 'string', required: true}
+ , status: {type: 'string', required: true}
+ , id: {type: 'string', required: true}
+ });
+Todo = geddy.model.register('Todo', Todo);
- <p>The first argument of the property method is the name of the property you want to define, the second is the data type, and the third is an options object which can contain shortcuts for validation. We want all of ours to be required, so we made sure that our options object has <code>required</code> set to <code>true</code>.</p>
+ <p>The `defineProperties` method takes any number of properties to be added to the model. The keys in the object will be added as properties on the model. The values are just objects that describe the properties. To define the type of the property, use the type option, we want ours to be strings. These properties should all be required, so set `required` to `true`.</p>
+ <p>To learn more, check out the <a href="">readme</a>.</p>
<p>There's also more detailed validation API. While we're here, lets use that API to set up some more validations:</p>

0 comments on commit bec0a56

Please sign in to comment.