FooEntity
and BarEntity
.bar
table has to contain a foo_id
column, or the other way around: A bar_id
column in the foo
table. In this example it will be foo_id
in the BarDefinition
.defineFields
methods of both entity definitions:FkField
, which basically is the mentioned foo_id
column. Its parameters are the name of the column in your database(snake_case), the property name in your definition (lowerCamelCase) and the respective definition class.OneToOneAssociationField
. Here you supply the name of the property, which should contain the associated entity, in your respective definition, e.g. in this case we want the FooDefinition
to appear in the foo
property of our entity. Following are foo_id
, which is the name of the column in the database, id
as the ID column in the referenced database (foo
in this case) and the referenced definition. The last parameter defines, if you want to automatically load this association every time you load a bar
entity. We've set this to false
.defineFields
method of the FooDefinition
:FkField
necessary.bar
entity comes with multiple foo
's. Therefore, you have to add a bar_id
column in your foo
table. In this example it will be bar_id
in the FooDefinition
.defineFields
methods of both entity definitions:IdField
, you only have to define the OneToManyAssociationField
in your BarDefinition
. Its paremeter are foos
, which is the property that will contain all FooEntity
's, the class name of FooDefinition
and the name of the column in the referenced table, which points to the definition itself.FooDefinition
now:IdField
, you can see a new FkField
, which is the field for the new bar_id
column. Its parameters are the name of the column in your database (snake_case), the property name in your definition (lowerCamelCase) and the respective definition class.OneToManyAssociationField
here now, we have to use the reverse side, which is ManyToOneAssociationField
. Here you have to apply the name of the property, which will contain the single BarDefinition
instance, the name of the column, which references to the inverse side entity (bar_id
), the class of the referenced definition and the name of the ID column in the definition's database table itself. You could add another boolean parameter here, which would define whether or not you want this association to always automatically be added and be loaded. This defaults to false
, since enabling this could come with performance issues.ManyToMany
associations require another, third entity to be available. It will be called FooBarMappingDefinition
and is responsible for connecting both definitions. It also needs an own database table.MappingEntityDefinition
, instead of the EntityDefinition
like in other entity definitions. The rest is quite the same: Your entity definitions needs an entity name, saved in ENTITY_NAME
, as well as the method defineFields
, which has to return a FieldCollection
.FkField
's. Its parameters are the name of the column in your database(snake_case), the property name in your definition (lowerCamelCase) and the respective definition class.ManyToOneAssociationField
's. Here you have to supply the name of the property in your entity, which should contain the entries, again the name of the column in the database and the definition again. The last parameter is most likely id
, which is the column name of the connected table. You could add another boolean parameter here, which would define whether or not you want this association to always automatically be added and be loaded. This defaults to false
, since enabling this could come with performance issues.ManyToManyAssociationField
to each of your definitions themselves, like in the following example:propertyName
: The name of the property in your entity, that will contain the associated entities.referenceDefinition
: The class of the associated definition.mappingDefinition
: The class of the mapping definition.mappingLocalColumn
: The name of the id column for the current entity, bar_id
if you're in the BarDefinition
.mappingReferenceColumn
: The name of the id column for the referenced entity.FooDefinition
:ManyToMany
association is now set up properly.