Skip to content

Associations Belongs To

lucasrenan edited this page Sep 14, 2010 · 2 revisions

Models examples

class Author < CouchRest::Model::Base
  property :name

  timestamps!
end

class Post < CouchRest::Model::Base
  belongs_to :author

  property :title
  property :content
  timestamps!

  view_by :title
end

A Post belongs to an Author

a = Author.new(:name => "Lucas")
a.save

p = Post.new(:title => "A blog post")
p.author = a
p.save

p.author.name # => "Lucas"
Clone this wiki locally