thecodingmachine/tdbm

Error when having a many to many relationships table between the same entity

ThibBal opened this issue · 2 comments

My model:

  • I have a geo_locations table which is composed by locations (cities, regions, countries, departments)
  • I have a table named geo_locations_relations, a many to many relationships table that is used to describe the relation between a location and one of its parents :
    ex: Paris 8e Arrondissement -> Paris
    ex2: Paris -> Ile de France
    ex3 : Paris 8e Arrondissement -> Ile de France

Structure of the geo_locations_relations table:

  • id PK
  • parent_location_id FK geo_locations
  • location_id FK geo_locations

Behaviour:

  • TDBM5 doesn't create the DAO of the table (that's normal) but generate a function in the AbstractGeoLocation Bean named getGeoLocationsByGeoLocationsRelations
  • But this function doesn't work. When executed, an error occurred:
    "There are many possible shortest paths between table 'geo_locations' and table 'geo_locations_relations'
    Path 1: geo_locations <--(location_id)-- geo_locations_relations
    Path 2: geo_locations <--(parent_location_id)-- geo_locations_relations"

What I would like: I don't know 🙃 Maybe two functions which specify the column to use for the path (the starting point):

  • getGeoLocationsByGeoLocationsRelationsUsingLocationId
  • getGeoLocationsByGeoLocationsRelationsUsingParentLocationId

Ok, this is a tricky one.
Especially, we should also make sure the setters/issers/adders are also correctly generated:

  • addGeoLocationsByGeoLocationsRelationsUsingLocationId
  • addGeoLocationsByGeoLocationsRelationsUsingParentLocationId

Also, I find the name of the methods clearly frightening. Maybe we should try to find shorter names (using an annotation like @jointable in the table comments?)

TODO: write a unit test for this case

#146