NAME
Mandel::Relationship::HasMany - A field relates to many other mongodb document
DESCRIPTION
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.
DATABASE STRUCTURE
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.
SYNOPSIS
Using DSL
Using object oriented interface
MyModel::Person->model->relationship(
"has_many"
,
"cats"
,
"MyModel::Cat"
,
);
See also "relationship" in Mandel::Model.
Methods generated
# 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;
ATTRIBUTES
Mandel::Relationship::HasMany inherits all attributes from Mandel::Relationship and implements the following new ones.
add_method_name
The name of the method used to add another document to the relationship.
search_method_name
The name of the method used to search related documents.
METHODS
Mandel::Relationship::HasMany inherits all methods from Mandel::Relationship and implements the following new ones.
monkey_patch
Add methods to "document_class" in Mandel::Relationship.
SEE ALSO
Mojolicious, Mango, Mandel::Relationship
AUTHOR
Jan Henning Thorsen - jhthorsen@cpan.org