The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mandel::Relationship::HasOne - A field relates to another mongodb document

DESCRIPTION

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.

DATABASE STRUCTURE

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"))
}

SYNOPSIS

Using DSL

package MyModel::Dinosaur;
use Mandel::Document;
has_one cat => 'MyModel::Cat';

Using object oriented interface

MyModel::Dinosaur->model->relationship(
  "has_one",
  "cat",
  "MyModel::Cat",
);

Methods generated

$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.

METHODS

monkey_patch

Add methods to "document_class" in Mandel::Relationship.

SEE ALSO

Mojolicious, Mango, Mandel::Relationship

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org