Self referencing Many to Many (m:n)

Posts   
 
    
Posts: 37
Joined: 21-Oct-2004
# Posted on: 02-Dec-2004 19:27:46   

I apologize if someone else has asked this before, but a quick search didn't yield an answer.

How can I achieve a self referencing many to many relationship with LLBLGen?

This is what I mean:

EntityTable

EntityID (PK) EntityName EtcField

JunctionTable

JunctionID (PK) PrimaryEntityID (FK for EntityID) SecondaryEntityID (FK for EntityID)

So Entity can have 0 or more "children" as well as 0 or more "parents" (each accessible through a field in the Entity BL). Is that clear enough? Is it possible with LLBLGen?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 03-Dec-2004 10:01:25   

These relations are not generated because these are resolvable from the 1.n or m:1 relations automatically. For example, you can retrieve the parents of an entity using an entity collection and a filter: say your entitytable is Customer and your junctiontable is Junction. You create a customercollection to hold the parents, and you construct a filter on junction.primaryentityid + you specify the relation customer-junction in the relationcollection. Then call getmulti.

If you run into problems constructing this, please let me know.

(note: the relation finder throws out m:n relations to self for the reason that these result in a filter on the same table. I'll check if your particular situation can be added to the designer's relation finder)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 37
Joined: 21-Oct-2004
# Posted on: 06-Dec-2004 01:00:20   

Thanks, I'll take a look at that.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 21-Dec-2004 01:22:02   

Otis wrote:

(note: the relation finder throws out m:n relations to self for the reason that these result in a filter on the same table. I'll check if your particular situation can be added to the designer's relation finder)

Frans,

I've hit this same problem with a adjacency list table... I would also like to be able to keep fields based on a m:n relation with self.

I understand you can get the collection easy enough but, not having the usual properties "ChildEntities" / "ParentEntities" on the Entity itself is a bit disappointing... cry

Is this a big deal to put back in?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-Dec-2004 10:17:37   

Well, it's a bit of a pain to generate them, as they aren't the usual m:n relations, so they require a special case in the templates and likely a new TDL statement.

Frans Bouma | Lead developer LLBLGen Pro
Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 21-Dec-2004 11:08:20   

Otis wrote:

Well, it's a bit of a pain to generate them, as they aren't the usual m:n relations, so they require a special case in the templates and likely a new TDL statement.

cry - I get the message!

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 15-Mar-2005 14:31:17   

Frans,

Is this issue addressed in the new Beta 2004.2?

Marcus

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 15-Mar-2005 15:10:33   

Marcus wrote:

Frans,

Is this issue addressed in the new Beta 2004.2?

Marcus

No, I'm sorry, this hasn't been addressed. Which is my fault, I never put it on the todo list. Though it will result in perhaps even more m:n relations which are already a plague for some projects.

Frans Bouma | Lead developer LLBLGen Pro
Mountain
User
Posts: 21
Joined: 01-Apr-2005
# Posted on: 01-Apr-2005 19:44:35   

Otis wrote:

Then call getmulti.

I'm using adapter and EntityCollectionBase2. I don't see a GetMulti. Does this not apply to adapter? Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 01-Apr-2005 22:08:20   

Mountain wrote:

Otis wrote:

Then call getmulti.

I'm using adapter and EntityCollectionBase2. I don't see a GetMulti. Does this not apply to adapter? Thanks.

Yes, you there have to call FetchEntityCollection.

Frans Bouma | Lead developer LLBLGen Pro