Naming Question

Posts   
 
    
csmith12
User
Posts: 33
Joined: 08-Dec-2003
# Posted on: 21-Mar-2005 15:31:47   

Experienced members,

Got a quick question about naming best practices.

I have a self referencing table.

Table Name - Part

Part_ID - PK Parent_ID FK -> Part_ID

When I generate the code (Self-Servicing) I have a collection on the part table as follows

PartParent_ID as PartCollection.

I was expecting it to be something like, Part.Part.Part.Part as an example to get to subparts.

Is there a best practice here, or am I missing something?

Using LLBLGen Pro. Version: 1.0.2004.1 Final Feb. 4th, 2005

Thanks,

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Mar-2005 16:37:37   

Your setup has multiple childs per parent, so it has to be a collection, so part.part.part.part can't be done, just part.ParentPart.ParentPart.ParentPart as that's an m:1 relation.

I'd name the collection SubParts.

Frans Bouma | Lead developer LLBLGen Pro
csmith12
User
Posts: 33
Joined: 08-Dec-2003
# Posted on: 21-Mar-2005 16:43:26   

Doh!

Sorry I was incorrect with my expectation.

I should have said this.

Part.Part(0).Part(0).Part(0)

Or


Dim Part as new PartEntity(1)
For Each P as PartEntity in Part.Part
  MsgBox(P.Part_ID)
  If P.Part.Count > 0 then
    MsgBox(P.Part(0).Parent_ID)
  End If
  Next

Just to show you the difference, here is what I am getting.


Dim Part as New PartEntity(1)
For Each P as PartEntity in Part.PartParent_ID ' Why is this collection named like this and not named Part?

  MsgBox(P.Part_ID)
  If P.PartParent_ID.Count > 0 then
    MsgBox(P.PartParent_ID(0).Parent_ID)
  End If

Next

As you can see, it works, but looks funny.

Oh, and is this documented anywhere? I can't seem to find anything on self referencing tables.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Mar-2005 10:09:44   

csmith12 wrote:

Doh!

Sorry I was incorrect with my expectation. I should have said this. Part.Part(0).Part(0).Part(0)

Or


Dim Part as new PartEntity(1)
For Each P as PartEntity in Part.Part
  MsgBox(P.Part_ID)
  If P.Part.Count > 0 then
    MsgBox(P.Part(0).Parent_ID)
  End If
  Next

Just to show you the difference, here is what I am getting.


Dim Part as New PartEntity(1)
For Each P as PartEntity in Part.PartParent_ID ' Why is this collection named like this and not named Part?

  MsgBox(P.Part_ID)
  If P.PartParent_ID.Count > 0 then
    MsgBox(P.PartParent_ID(0).Parent_ID)
  End If

Next

As you can see, it works, but looks funny.

1.0.2004.1 names fields mapped onto relations as: RelatedEntityNameFKField(s)name(s), so PartParentID is a logical way to name it. In 1.0.2004.2, (now in beta) it will be possible to specify a pattern how to name these fields.

So if you don't like the names now, you should rename the fields. In your situation, it is indeed an unfortunate name.

Frans Bouma | Lead developer LLBLGen Pro