Many-to-many relationship

Consider a many-to-many relationship where many employees belong to many departments. You can use code like the following to define a many-to-many mapping between the Department and Employee objects.

public class Employee 
    { 
        [Id] 
        [Column(name="ID")] 
        var id:uint; 
        [ManyToMany(targetEntity="Department", 
        fetchType="EAGER|LAZY(default)")] 
        [JoinTable(name="EMP_DEPT")] 
        [JoinColumn(name="EMPID", referencedColumnName="ID")] 
        [InverseJoinColumn(name="DEPID", referencedColumnName="DEPTID")] 
        var depts:ArrayCollection; 
    }

The default fetchType value is LAZY. See Lazy loading and fetch type for information on fetch types.

For a many-to-many relationship, you specify metadata like the following only on one of the entities and not both.

[JoinTable(name="ORDER_PRODUCT")] 
[JoinColumn(name="ORDER_ID",referencedColumnName="oid")] 
[InverseJoinColumn(name="PRODUCT_ID",referencedColumnName="pid")]

The[JoinColumn]tag specifies the foreign key column and all the attributes of the column tag. The [InverseJoinColumn] tag specifies the reference to the joining entity in the [JoinTable] tag. In this example, join table "EMP_DEPT" has a column named "DEPID", which refers to the "DEPTID" column of the Department table.

The[JoinTable] tag defines the join table for the many-to-many relationship specifying the join column and inverse join column. In this example, a join table named "EMP_DEPT" is created in the Offline SQLite DB with a many-to-many relationship between the Employee and Department tables.