Skip to content
Jon Clausen edited this page Dec 21, 2015 · 6 revisions

Usage

CBMongoDB will inspect your model properties to create your default document schema. All you need to do is add schema=true to your property and it will be included with the default document. You can either use a dot notation in the property name field for nested documents (infinite recursion) or specify parent="myParentProperty" (single-level recursion). For example a contact property might be:

/**Schema Properties**/
property name="first_name" schema=true validate="string";
property name="last_name" schema=true valiate="string";
property name="address" schema=true validate="struct";
/**Use either dot notation in the name or specify a 'parent' attribute as ways of creating nested documents**/
/**Dot Notation Examples**
property name="address.street" schema=true validate="string";
property name="address.city" schema=true validate="string";
property name="address.state" schema=true validate="string" length=2;
property name="address.postalcode" schema=true validate="zipcode";
property name="address.country" schema=true validate="string";
/**Parent attribute**/
property name="phone" schema=true validate="struct";
property name="home" schema=true parent="phone" validate="telephone";
property name="work" schema=true parent="phone" validate="telephone";
property name="mobile" schema=true parent="phone" validate="telephone";

properties may also be bound within a nested document by using a parent attribute. For example, using our country property:

property name="country" parent="address" schema=true validate="string";

Most of the time, however, dot-notated property names are more convenient since they more closely match the MongoDB query syntax.

Accessor Methods

Since Dot-Notation isn't practical when using accessor functions, property getters and setters are created for all schema properties, including those using dot notation. Document nesting is handled with the user of underscores (_) in place of the dot delimiters. For example, the property address.state would have the following accessor methods automatically generated:

getAddress_State() - the getter method

setAddress_State(required string value) - the setter method

CBMongoDB emulates many of the functions of the cborm ActiveEntity, to make getting started simple. There is also a chainable querying syntax which makes it easy to incorporate conditionals in to your search queries.

Clone this wiki locally