justnbusiness

Thursday, August 17, 2006

First post!

I've hit a sort of milestone today. I have end to end generation happening (as imperfect as it is) and it seems to be working quite well. I made some tough decisions today and trimmed quite a bit of fat but for the better I believe. The code is looking pretty good and I already have lots of ideas how to make it better. I also packaged everything you would need to start generating entities into a single demo zipfile here:

http://nbusiness.googlecode.com/svn/trunk/demo/NBusinessDemo.zip

The most important milestone of today, though, is probably solidly defining how relationships work. I started by really breaking down all of the possible relationship types, here is what I came up with:

  • 1:M (one to many)
  • M:1 (many to one)
  • M:M (many to many)
  • 1:1 (one to one)

After thinking about these relationships a bit I wrote up these little diagrams:


Basically this shows that the 1:M and the M:1 relationships are the same but just from different perspectives. In these relationships you have a Parent and a Child. The parent can have multiple children but the Children can only have 1 parent. So if you have two entities, A{aid} and B{bid, aid} you can establish a 1:M relationship with this syntax on A:

relationship BList with B on aid as child;

This establishes a child relationship called BList with B using the aid field to link them. And now for the M:1 on B:

relationship A with A on aid as parent;

Now the M:M relationship is significantly different. The idea here is that A can have many B's and B can have many A's. In this scenario neither one can be considered a parent or a child so instead we use the term 'sibling'. So if we have entities A{aid} and B{bid} then we can create a M:M relationship with this syntax:

on A: "relationship BList with B as sibling;"

on B: "relationship AList with A as sibling;"

Its important that both entities have the sibling relationship in this case and that they do not declare which fields to link on. In this case the Compiler will generate an internal intermediate type known as AB with fields for each id field in both entities. When adding an instance of B to the BList on A you will actually be adding an instance of AB but this is transparent to the developer.

It's also interesting to note that the 1:1 relationship never really comes up... Or at least this is what I'm thinking at this point. Typically in order to establish a 1:1 relationship at least one of the entities would have to have a field that corresponds to another entity but if only one has the field then that's just a 1:M, if they both have id's for each other then you could have a true 1:1 but that begs to have the question "why bother?" asked. If you had a 1:1 entity relationship you might as well just consider combining the two entities into 1. Consider this 1:1 relationship:

A{aid,bid,c} , B{bid,aid,d}

How is this actually different than just having:

A{aid,bid,c,d}

Its really not, therefore a 1:1 is useless and should be avoided and is intentionally left out of the semantics of E#. If I'm making a huge logic flaw here someone please let me know!

Anyrate I'm onto working on some better debugging for the compiler and then implementing the output of the relationships!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home