Mandel::Relationship::HasMany - A field relates to many other mongodb document
Mandel::Relationship::HasMany is a class used to describe the relationship between one document that has a relationship to many other documents. The connection between the documents is described in the database using DBRef.
A "person" that has many "cats" will look like this in the database:
mongodb# db.persons.find(); { "_id" : ObjectId("53529f28c5483e4977020000") } mongodb# db.cats.find({ "person.$id": ObjectId("53529f28c5483e4977020000") }) { "_id" : ObjectId("53529f28c5483e5077040000"), "person" : DBRef("persons", ObjectId("53529f28c5483e4977020000")) } { "_id" : ObjectId("6432574384483e4978010000"), "person" : DBRef("persons", ObjectId("53529f28c5483e4977020000")) }
A "has many" on one side is Mandel::Relationship::BelongsTo on the other side.
package MyModel::Person; use Mandel::Document; has_many cats => 'MyModel::Cat';
MyModel::Person->model->relationship( "has_many", "cats", "MyModel::Cat", );
See also "relationship" in Mandel::Model.
# non-blocking $person = MyModel::Person->new->add_cats(\%constructor_args, sub { my($person, $err, $cat_obj) = @_; # ... }); $person = MyModel::Person->new->add_cats($cat_obj, sub { my($person, $err, $cat_obj) = @_; # ... }); $person = MyModel::Cat->new->cats(sub { my($self, $err, $array_of_cats) = @_; # ... }); # blocking $cat_obj = MyModel::Person->new->add_cats(\%args); $cat_obj = MyModel::Person->new->add_cats($cat_obj); $array_of_cats = MyModel::Person->new->cats; $cat_collection = MyModel::Person->new->search_cats;
Mandel::Relationship::HasMany inherits all attributes from Mandel::Relationship and implements the following new ones.
The name of the method used to add another document to the relationship.
The name of the method used to search related documents.
Mandel::Relationship::HasMany 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.