As demonstrated on the previous chapter, an entity is a class that has a static method called setMapping(). This method will be used by wetland to create your entity's schema. In this chapter we will describe all the methods you can use to create your schema or to fetch information about your entity.


This method adds a relation to the mapping. The options available to create your relationship are described here. Although you can add your relations using this method, we recommend you to use .oneToOne(), .oneToMany(), .manyToMany() or .manyToOne() instead, for practical reasons.

mapping.addRelation('property', {targetedEntity: 'target', type: 'oneToMany', inversedBy: 'field'});


Sets cascade options to persist, delete or both. The cascade options must be passed as an array, regardless of how many cascade options the property has.

mapping.cascade('property', ['persist']);
// or


Maps an entity, allowing you to create a custom attributes for your entity. By using this method you can customize the repository, name, tableName and store attributes of your entity.

mapping.entity({repository: MyRepository, name: 'custom', store: MyOtherStore});


Extend the field options for a property. This method is used internally by other methods in the Mapping class. The field options can be found here.

mapping.extendField('property', {type: 'integer'});


Maps a field for an entity. Here is the list of field options you can use to map your property accordingly.

mapping.field('property', {type: 'string', size: 20});
// or
mapping.forProperty('property').field({type: 'string', size: 20});


Static method to get the mapping for a specific entity. Returns the entity's mapping instance.



Convenience method to map a property. This method stores the name of the property, erasing the need to specify a target when chaining manipulating methods to map a property.



This method maps the generated values of a property. It calls .extendField() on the property, adding a type to the generatedValue field.

mapping.generatedValue('id', 'autoIncrement');
// or


Gets the column name for a property.



Gets the name of the entity.



Gets the options for provided property. Returns an object of field options.



Gets the column name for given property.



Gets the fields for mapped entity, returning an array of objects containing the field options for each property.



Get the indexes for an entity, returning an object of indexes.



Get the join column for the relationship mapped via property, returning an object.



Get the join table for the relationship mapped via property, returning an object.

mapping.getJoinTable('property', entityManager);


Get all join tables, returning an array of objects.



Get the property that was assigned as the primary key.



Get the column name of the primary key.



Get the property name for a column name.



Get relations for mapped entity, returning an object.



Gets the Repository class for this mapping's entity.



Gets the name of the store mapped for this entity.



Returns the name of the table.



Get the target this entity is for.



Gets unique constraints, returning an object.



Convenience method to set auto increment. This method calls .extendField() on the property, setting the generatedValue field option to autoIncrement.

// or


Maps an index.

// Compound
mapping.index('idx_something', ['property1', 'property2']);

// Single
mapping.index('idx_something', ['property']);
mapping.index('idx_something', 'property');

// Generated index name "idx_property"
mapping.index(['property1', 'property2']);


Checks if property exists as a relation, returning a boolean.



Register a join column. This method calls .extendField() on the property, assigning the options given to the joinColumn field. The full list of options can be found here.

mapping.joinColumn('property', {});
// or


Register a join table. This method also uses .extendField() to assign the options given to the joinTable field. The full list of options can be found here.

mapping.joinTable('property', {});
// or


Convenience method to add a many-to-many relationship. A property in this kind of relationship can be either mappedBy or inversedBy, depending on if it is or not on the owning side, respectively.

mapping.manyToMany('property', {targetEntity: 'target', mappedBy: 'field'});
// or
mapping.forProperty('property').manyToMany({targetEntity: 'entity', mappedBy: 'field'});


Maps a many-to-one relationship. In this type of relationship, a property can only be inversedBy.

mapping.manyToOne('property', {targetEntity: 'target', inversedBy: 'field'});
// or
mapping.forProperty('property').manyToOne({targetEntity: 'target', inversedBy: 'field'});


Raw command for current timestamp.;


Maps a one-to-many relationship. In this case, the property is the owning side, so it can only be set as mappedBy.

mapping.oneToMany('property', {targetEntity: 'target', mappedBy: 'field'});
// or
mapping.forProperty('property').oneToMany({targetEntity: 'target', mappedBy: 'field'});


Maps a one to one relationship. A property in this kind of relationship can be either mappedBy or inversedBy, just like the many-to-many example.

mapping.oneToOne('property', {targetEntity: 'target', mappedBy: 'field'});
// or
mapping.forProperty('property').oneToOne({targetEntity: 'target', mappedBy: 'field'});


Maps a property to be the primary key. This method uses .extendField() to set the primary field to true.

// or


Maps unique constraint.

// Compound:
mapping.uniqueConstraint('something_unique', ['property1', 'property2']);

// Single:
mapping.uniqueConstraint('something_unique', ['property']);
mapping.uniqueConstraint('something_unique', 'property');

// Generated uniqueConstraint name:
mapping.uniqueConstraint(['property1', 'property2']);


Options Type
cascades array
comment string
defaultTo any
enumeration array
generatedValue string
joinColumn object
joinTable object
name string
nullable boolean
precision number
primary boolean
relationship object
scale number
size number
textType string
type string
unsigned boolean
[key: string] any

Join column

Options Type
indexName string
name string
nullable boolean
onDelete string
onUpdate string
referencedColumnName string
size number
type string
unique boolean

Join table

Options Type
inverseJoinColumns array
joinColumns array
name string


Options Type
inversedBy string
mappedBy string
targetEntity string, {new ()}
type string

results matching ""

    No results matching ""