Mandel::Relationship::HasOne - A field relates to another mongodb document
Mandel::Relationship::HasOne is a class used to describe the relationship between one document that has a relationship to one other documents. The connection between the documents is described in the database using DBRef.
A "dinosaur" that has one "cat" will look like this in the database:
mongodb# db.dinosaurs.find({ }) { "_id" : ObjectId("5352b4d8c5483e4502010000") } mongodb# db.cats.find({ "dinosaur.$id": ObjectId("53529f28c5483e4977020000") }) { "_id" : ObjectId("5352b4d8c5483e4502040000"), "dinosaur" : DBRef("dinosaurs", ObjectId("5352b4d8c5483e4502010000")) }
package MyModel::Dinosaur; use Mandel::Document; has_one cat => 'MyModel::Cat';
MyModel::Dinosaur->model->relationship( "has_one", "cat", "MyModel::Cat", );
$cat = MyModel::Dinosaur->new->cat(\%args, $cb); $cat = MyModel::Dinosaur->new->cat($person_obj, $cb); $person_obj = MyModel::Dinosaur->new->cat(\%args); $person_obj = MyModel::Dinosaur->new->cat($person_obj); $person = MyModel::Dinosaur->new->cat; $self = MyModel::Dinosaur->new->cat(sub { my($self, $err, $person) = @_; });
See also "relationship" in Mandel::Model.
Add methods to "document_class" in Mandel::Relationship.
Mojolicious, Mango, Mandel::Relationship
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mandel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mandel
CPAN shell
perl -MCPAN -e shell install Mandel
For more information on module installation, please visit the detailed CPAN module installation guide.