NAME

Mongol::Cookbook - Mongol tips and tricks

TIPS

Models base class

package Models::Base {
	use Moose;

	extends 'Mongol::Model'

	__PACKAGE__->meta()->make_immutable();
}

package Models::User {
	use Moose;

	extends 'Models::Base';

	with 'Mongol::Roles::Core';

	has 'username' => (
		is => 'ro',
		isa => 'Str',
		required => 1
	);

	has 'password' => (
		is => 'ro',
		isa => 'Str',
		required => 1,
	);

	...

	__PACKAGE__->meta()->make_immutable();
}

Save/Remove triggers

Serialize your instances

Somewhere in the Mojolicious world...

sub action {
	my $self = shift();

	...

	my $id = $self->param( 'user_id' );
	my $user = Models::User->retrieve( $id )
		->serialize();

	return $self->render( json => $user );
}

Custom ids

package Models::User {
	use Moose;

	extends 'Mongol::Model';

	with 'Mongol::Roles::Core';
	with 'Mongol::Roles::UUID';

	has 'username' => (
		is => 'ro',
		isa => 'Str',
		required => 1,
	);

	has 'password' => (
		is => 'ro',
		isa => 'Str',
		required => 1,
	);

	...

	__PACKAGE__->meta()->make_immutable();
}

1;

SEE ALSO

AUTHOR

Tudor Marghidanu <tudor@marghidanu.com>