[NFR] Implement Phalcon\Mvc\Collection\Model
Document-oriented databases like MongoDB are very different from SQL databases by their structure. NoSQL collection is not one unit of data like SQL table, NoSQL collection is complex of several models.
For example we have photo gallery and any photography belongs to the some category. It is two different models.
For SQL it is two different tables, but for databases like Mongo it's one collection which consists of two models:
category = {
title : 'some category name',
photos : [
{
title : 'Beautiful girl',
src : 'girl.jpg'
},
{
title : 'Chevrolet Camaro',
src : 'camaro.jpg'
}
]
};
It is Category model and Photo model. And any of them has it's own structure and business logic.
I believe that abstraction should look like this:
// this is collection
class Categories extends Phalcon\Mvc\Collection
{
public $title;
public $photos;
public function beforeValidationOnCreate()
{
// ...
}
}
// this is model, not collection
class Photos extends Phalcon\Mvc\Collection\Model
{
public $title;
public $src;
public function beforeValidationOnCreate()
{
// ...
}
}
$category = new Categories;
$category->title = 'some category name';
$photo = new Photos;
$photo->title = 'Beautiful girl';
$photo->src = 'girl.jpg';
$category->addPhotos($photo);
// or just
$category->photos[] = $photo;
$category->save();
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
SQL and noSQL are different in some aspect, but cleary both are data storage mechanism and can use similar API.
UnQL (Unstructured Query Language), a specification for a query language for NoSQL databases. Like XQuery it is designed to query collections (versus tables) of documents (versus rows) with loosely defined fields (versus columns). UnQL is claime to be a superset of SQL within which SQL is a very constrained type of UnQL for which the queries always return the same fields UnQL is claimed to be a superset of SQL within which SQL is a very constrained type of UnQL for which the queries always return the same fields
@salarmehr you are wrong
collections (versus tables) of documents (versus rows)
Document is not one row!
For my example Categories document is like SQL:
SELECT
*
FROM
cetegories c
LEFT OUTER JOIN photos p ON p.category_id = c.id
So it's like "belongs to", not "row=document"
Several Photos belongs to one Category in the context of a single document.
@Agent-J Thant paragraph is from Wikipedia (nosql page). Comparing tables with collection and row with document is also frequent in mongodb documentation. Also nether are equivalent, they have some similarities.
Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues