Many to many association not working

Hello Team,

I created a many to many association between two entities i.e. between Airport and Airline. In airport edit screen I created a tab of airline which I can create multiple
airlines for a particular airport. When I am creating a new airport with some airlines as many I want, all records are being saved successfully i.e. in {PROJECT_NAME}_AIRPORT,
{PROJECT_NAME}_AIRLINE and third table which keeps primary ID for both table({PROJECT_NAME}_AIRPORT_AIRLINE_LINK). But again when I am trying to add some more terminals for created airport i.e. when I went for edit the airport, records to the third({PROJECT_NAME}_AIRPORT_AIRLINE_LINK) table are not being generating.
For more reference I have attached a sample project for it.
Can anyone please provide some suggestion what I am doing wrong here? If anyone need more information please let me know.

manytomanyassociation.zip (403.0 KB)

Thanks,
Subrat

Hi Subrat,

This use case (when you create a linked entity for many-to-many association instead of select it using Add action) is not handled fully automatically. You should add the listener to modification of the nested datasource and make the entity in the master datasource modified. It will make the editor to save the master entity with the associated collection.

public class AirportEdit extends AbstractEditor<Airport> {

    @Inject
    private CollectionDatasource<Airline, UUID> airlineDs;

    @Inject
    private Datasource<Airport> airportDs;

    @Override
    public void ready() {
        super.ready();

        airlineDs.addCollectionChangeListener(e -> {
            ((DatasourceImplementation<Airport>) airportDs).modified(getItem());
        });
    }
}

See the whole project attached.
manytomanyassociation.zip (90.8 KB)

1 Like

Hi Konstantin,

Thanks for your help. I tried it and it is working now.

Thanks,
Subrat