Skip to content

Associations Collection Of

lucasrenan edited this page Sep 14, 2010 · 1 revision

Models examples

class Post < CouchRest::Model::Base
  collection_of :tags

  property :title
  property :content
  timestamps!

  view_by :title
end

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

  view_by :name
end

A Post has a collection of Tags

tags = [
 Tag.create(:name => "ruby"),
 Tag.create(:name => "rails3"),
 Tag.create(:name => "couchdb")
]

post = Post.new(:title => "Another blog post")
post.tags = tags
post.save

post.tags.collect{|p| p.name} # => ["ruby", "rails3", "couchdb"]
post.tags.first.name # => "ruby"
Clone this wiki locally