Mapping

The mapping methods are used to create the entity's schema. Usage examples can be found on our Cookbook.

.addRelation()

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

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

.cascade()

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
mapping.forProperty('property').cascade(['persist']);

.entity()

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});

.extendField()

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'});

.field()

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});

forEntity()

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

forEntity('entity');

.forProperty()

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.

mapping.forProperty('property');

.generatedValue()

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
mapping.forProperty('id').generatedValue('autoIncrement');

.getColumnName()

Gets the column name for a property.

mapping.getColumnName('property');

.getEntityName()

Gets the name of the entity.

mapping.getEntityName();

.getField()

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

mapping.getField('property');

.getFieldName()

Gets the column name for given property.

mapping.getFieldName('property');

.getFields()

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

mapping.getFields();

.getIndexes()

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

mapping.getIndexes();

.getJoinColumn()

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

mapping.getJoinColumn('property');

.getJoinTable()

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

mapping.getJoinTable('property');

.getPrimaryKey()

Get the property that was assigned as the primary key.

mapping.getPrimaryKey();

.getPrimaryKeyField()

Get the column name of the primary key.

mapping.getPrimaryKeyField();

.getPropertyName()

Get the property name for a column name.

mapping.getPropertyName('column');

.getRelations()

Get relations for mapped entity, returning an object.

mapping.getRelations();

.getRepository()

Gets the Repository class for this mapping's entity.

mapping.getRepository();

.getStoreName()

Gets the name of the store mapped for this entity.

mapping.getStoreName();

.getTableName()

Returns the name of the table.

mapping.getTableName();

.getTarget()

Get the target this entity is for.

mapping.getTarget();

.getUniqueConstraints()

Gets unique constraints, returning an object.

mapping.getUniqueConstraints();

.increments()

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

mapping.increments('property');
// or
mapping.forProperty('property').increments();

.index()

Maps an index. If you decide not to choose your index name, wetland will do it for you. The index name will then be 'idx_' followed by your property names separated by an underscore.

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

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

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

.isRelation()

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

mapping.isRelation('property');

.joinColumn()

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
mapping.forProperty('property').joinColumn({});

.joinTable()

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
mapping.forProperty('property').joinTable({});

.manyToMany()

Maps 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'});

.manyToOne()

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'});

.now()

Raw command for current timestamp.

mapping.now();

.oneToMany()

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'});

.oneToOne()

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'});

.primary()

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

mapping.primary('property');
// or
mapping.forProperty('property').primary();

.uniqueConstraint()

Maps a unique constraint. If you don't wish to use a custom name for your constraint, wetland will use your property names to name it for you, separating them with an underscore and adding '_unique' at the end.

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

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

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

Field options

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

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

Join table options

Options Type
inverseJoinColumns array
joinColumns array
name string

Relationship options

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

results matching ""

    No results matching ""