Tuesday, October 27, 2009

One to Many relationship in liftweb

Most of the other examples don't follow all the way through, leaving you at the "Oh gee, the mapping is done, now how do I get to select the many". My example is not to show the One to Many where the Many are dependant on the one, but rather choices that the one can belong to the one. So for instance you have a Party which has a many to many relationship with PartyType. However, a Party can have different types at different times, so you need a one to many from the party to some intermediate class (we'll call it PartyClassification), and then from PartyClassification to Party Type.
Something this: Party[1]->[N]PartyClassification[N]<-[1]PartyType.
The Party[1]->[N]PartyClassification part is fairly easy to do, and I'll cover it later. However the PartyClassification[N]<-[1]PartyType is more interesting. You can't create a PartyClassification without a PartyType, and you have to present the user with a selection of PartyTypes that the PartyClassification can have.
Now, for the example I'm going to use One[1]->[N]Many as the actual names. I could use PartyClassification and PartyType, however whenever I follow examples with "real" names, I sometimes forget which is the many, and which is the one. I'll assume the same happens to you, and keep it simple.
So we start with a fresh mvn archetype install.