cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Many-To-Many Relationships and editing them via ToManyList
Date Tue, 28 Aug 2012 04:57:48 GMT
Hi Friedrich,

I would recommend going with the generated methods instead of using List API for list modification.
Cayenne makes no guarantees about the later approach correctness.

Cheers,
Andrus

On Aug 26, 2012, at 2:17 PM, Friedrich Röhrs wrote:

> Hi,
> 
> I am a bit confused about ToManyList and if I have understood
> correctly how they work.
> 
> My Tables are as follows:
> 
> PERSON (PK ID), BUILDING (PK ID), PERSON_BUILDING (PK PERSON_ID, BUILDING_ID).
> 
> The Classes generated from this are: Person and Building.
> 
> I have modelled it so that Person.getBuildings() would return a list
> of buildings that person has access to (going through PERSON_BUILDING
> via flattened relationships) and Building.getPersons() would get the
> persons allowed into that building.
> 
> For me the simplest (and most natural) way of adding/removing access
> would be something like this:
> 
> Person p = PersonService.getById(id);
> Building b = BuildingService.getById(id2);
> p.getBuildings().add(b);
> 
> Person p2 = PersonService.getById(id3);
> List<Building> bs = BuildingService.getAllById(listOfIds);
> 
> p2.getBuildings().removeAll(bs);
> 
> (and then commit).
> 
> For my simple test this seems to work. But when cayenne generates the
> domain classes it creates additional methods:
> 
> Person.removeFromBuildings(Building b);
> Person.addToBuildings(Building b);
> 
> and same for Buildings. This seems redundant if one can already do
> this by editing the list to me, so I was a bit confused.
> 
> Furthermore I found a Mailinglist entry that said if one doesn't use
> the provider methods, reverse relationships are not removed.
> 
> For me the reverse relationship of Person -> Building is Building ->
> Person, but this hinges on the same table entry in PERSON_BUILDING, so
> if I delete it, the reverse Relationship should be gone too, no?
> 
> Also all examples in the docs and demos, use the generated methods, so
> I am unsure if I can use the ToManyList directly or if that will
> somehow break something later.
> 
> Thanks,
> 
> Friedrich
> 


Mime
View raw message