|
NAMEMongoose::Join - simple class relationship resolverSYNOPSISpackage Author; use Moose; with 'Mongoose::Document'; has 'articles' => ( is => 'rw', isa => 'Mongoose::Join[Article]', default => sub { Mongoose::Join->new( with_class => 'Article' ) } ); DESCRIPTIONThis module can be used to establish relationships between two "Mongoose::Document" classes. It should not be used with "Mongoose::EmbeddedDocument" classes.All object relationships are stored as reference $id arrays into the parent object. This translates into a slight performance hit when loading the parent class, but not as much as loading all objects at one as when using an "ArrayRef". Attention: the relationship attribute needs to be initialized to an instance of "Mongoose::Join" before it can be used. Mongoose::ClassTake a look at Mongoose::Class, it has nice syntatic sugar that does most of the initialization behind the scenes for you.METHODSaddAdd (join) a Mongoose::Document object for later saving.Saving the parent Mongoose::Document will save both. my $author = Author->new; $author->articles->add( Article->new ); $author->save; # saves all objects removeDelete from the relationship list.my $author = Author->find_one; my $first_article = $author->articles->find_one; $author->articles->remove( $first_article ); findRun a MongoDB "find" on the joint collection.# searches for articles belonging to this collection my $cursor = $author->articles->find({ title=>'foo article' }); while( my $article = $cursor->next ) { ... } Returns a Mongoose::Cursor. countCount relations.find_oneJust like find, but returns the first row found.firstAlias to "find_one"$first_cd = $artist->cds->first; allSame as "find", but returns an ARRAY with all the results, instead of a cursor.my @cds = $artist->cds->all; hash_onSame as "all", but returns a HASH instead of an ARRAY. The hash will be indexed by the key name sent as the first parameter. The hash value contains exactly one object. In case duplicate rows with the same key value are found, the resulting hash will contain the first one found.# ie. returns $cds{'111888888292adf0000003'} = <CD Object>; my %cds = $artist->cds->hash_on( '_id' => { artist=>'Joe' }); # ie. returns $joe_cds{'Title1'} = <CD Object>; my %joe_cds = $artist->cds->hash_on( 'title' => { artist=>qr/Joe/ }); hash_arraySimilar to "hash_on", but returns a hash with ALL rows found, grouped by the key.# ie. returns $cds{'Title1'} = [ <CD1 Object>, <CD2 Object>, ... ]; my %cds = $artist->cds->hash_array( 'title' => { artist=>'Joe' }); Hash values are ARRAYREFs with 1 or more rows. queryRun a MongoDB "query" on the joint collection.collectionReturns the MongoDB::Collection for the joint collection.with_collection_nameReturn the collection name for the joint Mongoose::Document.
Visit the GSP FreeBSD Man Page Interface. |