We will not discuss ODM too much. It mostly supports the same actions as ORM. CRUD operations can be done in the same way as we did with ORM. Of course, we can't use transactions here, since MongoDB is not a transactional database.
Another important thing is that we need to declare the variables as public, not protected, as we did with the article model. This is the case in Phalcon version 1.3.4, but maybe in version 2.0, things will change.
A big difference is in the parameters that we pass to a find()
method. Suppose we used something like the following code for ORM:
Article::find([ 'article_slug' => 'test-article-title' ]);
For the ODM, we need to do it like this:
Article::find([ [ 'article_slug' => 'test-article-title' ] ]);
Note
Please read more about these differences at http://docs.phalconphp.com/en/latest/reference/odm.html and http://php.net/manual/ro/mongo.sqltomongo.php.
Because we will be using MongoDB later, for now, we will just set up the connection...