Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ h1. MongoRecord
MongoRecord is a PHP Mongo ORM layer built on top of the PHP "Mongo PECL extension":http://pecl.php.net/package/mongo

MongoRecord is an extraction from online classifieds site "Oodle":http://www.oodle.com. Oodle's requirements for a manageable, easy to understand interface for dealing with the super-scalable Mongo datastore was the primary reason for MongoRecord. It was developed to use with PHP applications looking to add Mongo's scaling capabilities while dealing with a nice abstraction layer.
*This branch is folked from lunaru/MongoRecord(https://github.com/lunaru/MongoRecord), and add relation features(has_many,has_one,belong_to)*


h2. Features

Expand All @@ -11,6 +13,7 @@ h2. Features
* Validations
* Callbacks
* Sorting, offsets, limits
* Relations(has_many,has_one,belong_to)

h2. Requirements

Expand Down Expand Up @@ -104,6 +107,64 @@ $person = new Person();
$person->setName("Bob");
$person->save(); // fails!

h3. Relations

Relations can be set to support belong_to,has_many,has_one, see below sample:

pre..
class Student extends BaseMongoRecord
{
protected $belong_to=array('School');
/**
can add more targets with-> $belong_to=array('ClsA','ClsB',...)
below methods are genereated automaticlly:
$this->getSchool();//return school
$this->setSchool($school);//return $this
*/
}

class School extends BaseMongoRecord
{
protected $has_many=array('Student');
/**
Can add more targets with-> $has_many=array('ClsA','ClsB',...)
below methods are genereated automaticlly:
$this->getStudents();//return MongoRecordIterator
$this->setStudents($stuarray);//parm is array of students,return $this
$this->createStudent();//new student and return it,return student
$this->addStudent($stu);//parm is student instante,return $this
$this->removeStudent($stu);//parm is student instant,return $this
*/
}

$school=new School();
$school->setName('fooschool');
$school->createStudent()->setName("foostu1")->save();
$school->createStudent()->setName("foostu2")->save();
$school->save();

$students=$school->getStudents();//=>MongoRecordIterator
var_dump($students->count());//=>2
foreach($students as $student)
{
var_dump($student);//=>foostu1,foostu2
}

$student=new Student();
$student->setName('foostu3')->save();
$school->addStudent($student);
$students=$school->getStudents();//=>MongoRecordIterator

var_dump($students->count());//=>3
foreach($students as $stu)
{
var_dump($stu);//=>foostu1,foostu2,foostu3
}

$student->setSchool($school)->save();
var_dump($student->getSchool()->getName());//=>'fooschool'


h3. Callbacks

Callbacks can be added for the following events:
Expand Down
Loading