New MongoDB ODM Project


This tutorial shows how simple it is to start a new project using Skipper. We are going to create MongoDB ODM project with two bundles and four entities. Export of the created project to MongoDB ODM .xml schema definition files is also part of this tutorial. We are also going to show the annotations export.

Hint: See the ODM Model basics for detailed description of the ODM elements (e.g. bundle, entity).

New project

First step is to create new project with MongoDB ODM framework support. Simply select the New ODM Project from File menu and do the following steps.

Select New MongoDB ODM Project in Skipper definition files import wizard
Select MongoDB ODM in Skipper schema import wizard
Select Symfony framework in Skipper definitions import wizard

Select project name and directory in Skipper MongoDB ODM schema definition files export wizard
New project summary screen in Skipper schema definition files export wizard
New project with default model

Application model design

Now we are going to design a simple application with two bundles and four entities. The first bundle will serve as contact records, the second bundle as an ecommerce logic. Contact bundle keeps data about customers and their addresses, Ecommerce bundle keeps data about orders and their items. Ecommerce order also has a relation with contact to store order owner. You can do it this way:

Select Skipper entity tool
Configure new MongoDB ODM entity in Skipper visual model
New MongoDB ODM entity created in Skipper visual model
Select Skipper association tool
Configure new MongoDB ODM association in Skipper visual model
New MongoDB ODM association created in Skipper visual model
Select Skipper comment tool
Configure new Skipper comment
New Skipper comment created
Select MongoDB ODM bundle tool in Skipper visual model
Configure new MongoDB ODM bundle in Skipper visual model
New MongoDB ODM bundle created in Skipper visual model
Create MongoDB ODM ecommerce entities in Skipper visual model
Contact to order association in Skipper visual model

Export model

Now when you have created the application model, next step is to export it to MongoDB ODM schema definition files. Before Skipper generates all the files for you, it is necessary to configure schema file destinations and export formats.

Skipper exports single schema file for each MongoDB ODM entity. This means that our project will export four schema definition files (one for each entity in the model). Each bundle can have its own export path which is relative to project root directory and its own export format. For MongoDB ODM it is XML, YML and annotations.

Edit MongoDB ODM bundle settings
Configure MongoDB ODM shema definitions export settings
Use export to ODM
MongoDB ODM schema definitions export settings window
MongoDB ODM definitions export results
Exported MongoDB ODM XML files

And here is an example of Address entity. As you can see everything is well formatted and exported in MongoDB ODM XML format.

<doctrine-mongo-mapping ...>
	<document name="Address">
		<field name="id" id="true" type="int"/>
		<field name="name" type="string"/>
		<field name="street" type="string"/>
		<field name="city" type="string"/>
		<field name="postcode" type="string"/>
		<field name="country" type="string"/>
		<reference-one field="contact" target-document="Contact" inversed-by="address"/>
	</document>

</doctrine-mongo-mapping>

Skipper can export schema definitions to all supported MongoDB ODM export formats - XML, YML or annotations. If you select annotations format export will look like this:

<?php
use Doctrine\ODM\MongoDB\Mapping\Annotations AS ODM;

/**
 * @ODM\Document
 */
class Address
{
    /**
     * @ODM\Id(type="int")
     */
    private $id;

    /**
     * @ODM\Field(type="string")
     */
    private $name;

    /**
     * @ODM\Field(type="string")
     */
    private $street;

    /**
     * @ODM\Field(type="string")
     */
    private $city;

    /**
     * @ODM\Field(type="string")
     */
    private $postcode;

    /**
     * @ODM\Field(type="string")
     */
    private $country;

    /**
     * @ODM\ReferenceOne(targetDocument="Contact", inversedBy="address")
     */
    private $contact;
}

Conclusion

This short tutorial shows that to create new project and export it to schema definition files takes no more than five minutes in Skipper (if it is your first try, it may take little longer). Compare it with manual writing of such small project, and the acceleration of work is breathtaking. And in addition, you can concentrate only on the creative part of your work.

Video Tutorials

Create new project

Export project