Permalink
Browse files

Minor formatting fix for comments

  • Loading branch information...
1 parent 07e0cc9 commit fbff36331bf368efeeb4d68811db48d8c4a527e9 @dkubb dkubb committed Sep 13, 2010
@@ -75,7 +75,7 @@ command-line so that you can browse your resources without the need to load up
the entire environment of your application. Here's an example session:
{% highlight bash linenos %}
-$ dm mysql://root@localhost/great_musicians # connecting to a repository
+$ dm mysql://root@localhost/great_musicians # connecting to a repository
{% endhighlight %}
An IRB session boots up...
View
@@ -72,7 +72,7 @@ class Comment
property :id, Serial
property :rating, Integer
- belongs_to :post # defaults to :required => true
+ belongs_to :post # defaults to :required => true
def self.popular
all(:rating.gt => 3)
@@ -315,14 +315,14 @@ a hash of attributes, you can either call the `new` or the `create` method direc
on the association, passing it the attributes in form of a hash.
{% highlight ruby linenos %}
-post = Post.get(1) # find a post to add a comment to
+post = Post.get(1) # find a post to add a comment to
# This will add a new but not yet saved comment to the collection
comment = post.comments.new(:subject => 'DataMapper ...')
# Both of the following calls will actually save the comment
-post.save # This will save the post along with the newly added comment
-comment.save # This will only save the comment
+post.save # This will save the post along with the newly added comment
+comment.save # This will only save the comment
# This will create a comment, save it, and add it to the collection
comment = post.comments.create(:subject => 'DataMapper ...')
@@ -333,11 +333,11 @@ to the association using the `<<` method. You still need to manually save the pa
resource to persist the comment as part of the related collection.
{% highlight ruby linenos %}
-post.comments << comment # append an already existing comment
+post.comments << comment # append an already existing comment
# Both of the following calls will actually save the comment
-post.save # This will save the post along with the newly added comment
-post.comments.save # This will only save the comments collection
+post.save # This will save the post along with the newly added comment
+post.comments.save # This will only save the comments collection
{% endhighlight %}
Customizing Associations
@@ -430,9 +430,9 @@ class Post
# presence of the attribute value.
belongs_to :blog, 'Blog',
- :parent_key => [:id], # in the remote model (Blog)
- :child_key => [:blog_id], # local to this model (Post)
- :required => true # the blog_id must be present
+ :parent_key => [:id], # in the remote model (Blog)
+ :child_key => [:blog_id], # local to this model (Post)
+ :required => true # the blog_id must be present
end
{% endhighlight %}
@@ -449,7 +449,7 @@ automatically makes it `:required => true` as well.
{% highlight ruby linenos %}
class Post
include DataMapper::Resource
- belongs_to :blog, :key => true # 'blog_id' is the primary key
+ belongs_to :blog, :key => true # 'blog_id' is the primary key
end
class Person
@@ -461,8 +461,8 @@ class Authorship
include DataMapper::Resource
- belongs_to :post, :key => true # 'post_id' is part of the CPK
- belongs_to :person, :key => true # 'person_id' is part of the CPK
+ belongs_to :post, :key => true # 'post_id' is part of the CPK
+ belongs_to :person, :key => true # 'person_id' is part of the CPK
end
{% endhighlight %}
@@ -508,8 +508,8 @@ class Authorship
include DataMapper::Resource
- belongs_to :post, :key => true # 'post_id' is part of the CPK
- belongs_to :person, :key => true # 'person_id' is part of the CPK
+ belongs_to :post, :key => true # 'post_id' is part of the CPK
+ belongs_to :person, :key => true # 'person_id' is part of the CPK
end
{% endhighlight %}
@@ -543,10 +543,10 @@ In a way, it acts like a database view in that respect.
{% highlight ruby linenos %}
@post = Post.first
-@post.comments # returns the full association
-@post.comments.all(:limit => 10, :order => [ :created_at.desc ]) # return the first 10 comments, newest first
-@post.comments(:limit => 10, :order => [ :created_at.desc ]) # alias for #all, you can pass in the options directly
-@post.comments.popular # Uses the 'popular' finder method/scope to return only highly rated comments
+@post.comments # returns the full association
+@post.comments.all(:limit => 10, :order => [ :created_at.desc ]) # return the first 10 comments, newest first
+@post.comments(:limit => 10, :order => [ :created_at.desc ]) # alias for #all, you can pass in the options directly
+@post.comments.popular # Uses the 'popular' finder method/scope to return only highly rated comments
{% endhighlight %}
Querying via Relationships
@@ -61,9 +61,9 @@ If you want it to raise exceptions instead, you can instruct datamapper to do so
either globally, on a per-model, or on a per-instance basis.
{% highlight ruby linenos %}
-DataMapper::Model.raise_on_save_failure = true # globally
-Zoo.raise_on_save_failure = true # per-model
-zoo.raise_on_save_failure = true # per-instance
+DataMapper::Model.raise_on_save_failure = true # globally across all models
+Zoo.raise_on_save_failure = true # per-model
+zoo.raise_on_save_failure = true # per-instance
{% endhighlight %}
If DataMapper is told to `raise_on_save_failure` it will raise the following when
View
@@ -31,11 +31,11 @@ class Post
# set the storage name for the :legacy repository
storage_names[:legacy] = 'tblPost'
- property :id, Serial, :field => :pid # use the 'pid' field in the data-store
+ property :id, Serial, :field => :pid # use the 'pid' field in the data-store
# for the id property.
- belongs_to :user, :child_key => [ :uid ] # use a property called 'uid' as the
- # child key the foreign key
+ belongs_to :user, :child_key => [ :uid ] # use a property called 'uid' as the
+ # child key the foreign key
end
{% endhighlight %}
View
@@ -102,7 +102,7 @@ DataMapper's solution is to let you chain association calls:
{% highlight ruby linenos %}
zoo = Zoo.first
-zoo.exhibits.animals # retrieves all animals for all exhibits for that zoo
+zoo.exhibits.animals # retrieves all animals for all exhibits for that zoo
{% endhighlight %}
This has great potential for browsing collections of content, like browsing all
@@ -61,8 +61,8 @@ Triggers that generate validator creation:
# :size is a synonym to :length
# implicitly creates a validates_format
- :format => :email_address # predefined regex
- :format => :url # predefined regex
+ :format => :email_address # predefined regex
+ :format => :url # predefined regex
:format => /\w+_\w+/
:format => lambda {|str| str }
:format => Proc.new { |str| str }
View
@@ -72,10 +72,10 @@ whatever you want.
class Post
include DataMapper::Resource
- property :id, Serial # An auto-increment integer key
- property :title, String # A varchar type string, for short strings
- property :body, Text # A text block, for longer string data.
- property :created_at, DateTime # A DateTime, for any date you might like.
+ property :id, Serial # An auto-increment integer key
+ property :title, String # A varchar type string, for short strings
+ property :body, Text # A text block, for longer string data.
+ property :created_at, DateTime # A DateTime, for any date you might like.
end
class Comment

0 comments on commit fbff363

Please sign in to comment.