- Fixed minor bugs on ActiveMongo
[activemongo.git] / sample / blog / Post.php
blobe5f96f985ebc910329c78e20910aa34ade7fd02d
1 <?php
3 class PostModel extends ActiveMongo
5 public $title;
6 public $uri;
7 public $author;
8 public $comment;
10 function author_filter(&$value, $old_value)
12 if (!$value instanceof MongoID) {
13 if (!$value InstanceOf AuthorModel) {
14 throw new Exception("The author property must be an AuthorModel object");
16 $value = $value->getID();
20 function getCollectionName()
22 return 'post';
25 function updateAuthorInfo(MongoID $id)
27 $author = new AuthorModel;
28 $author->find($id);
30 $document = array(
31 '$set' => array(
32 'author_name' => $author->name,
33 'author_username' => $author->username,
37 $filter = array(
38 'author' => $id,
41 $this->_getCollection()->update($filter, $document, array('multiple' => true));
43 return true;
46 function on_save()
48 $this->updateAuthorInfo($this->author);
51 function setup()
53 $collection = & $this->_getCollection();
54 $collection->ensureIndex(array('uri' => 1), array('unique'=> 1, 'background' => 1));