Mandel::Relationship::BelongsTo - A document is owned by another mongodb document
Mandel::Relationship::BelongsTo is a class used to describe the relationship between one document that belongs to another document. The connection between the documents is described in the database using DBRef.
A "cat" that belongs to a "person" will look like this in the database:
mongodb# db.persons.find(); { "_id" : ObjectId("5352abb0c5483e591a010000") } mongodb# db.cats.find({ "person.$id": ObjectId("5352abb0c5483e591a010000") }) { "_id" : ObjectId("5352abb0c5483e591a020000"), "person" : DBRef("persons", ObjectId("5352abb0c5483e591a010000")) }
package MyModel::Cat; use Mandel::Document; belongs_to owner => 'MyModel::Person';
MyModel::Cat ->model ->relationship(belongs_to => owner => 'MyModel::Person');
See also "relationship" in Mandel::Model.
# non-blocking set $cat = MyModel::Cat->new->owner(\%args, sub { my($cat, $err, $person_obj) = @_; # ... }); $cat = MyModel::Cat->new->owner($person_obj, sub { my($cat, $err, $person_obj) = @_; # ... }); # non-blocking get $cat = MyModel::Cat->new->owner(sub { my($cat, $err, $person_obj) = @_; # ... }); # blocking set $person_obj = MyModel::Cat->new->owner(\%args); $person_obj = MyModel::Cat->new->owner($person_obj); $person_obj = MyModel::Cat->new->owner($bson_oid); # blocking get $person = MyModel::Cat->new->owner;
Mandel::Relationship::BelongsTo inherits all attributes from Mandel::Relationship and implements the following new ones.
The name of the field in this class which hold the "_id" to the related doc.
Mandel::Relationship::BelongsTo inherits all methods from Mandel::Relationship and implements the following new ones.
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.