Re: [Modeling-users] Intro/Question
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-05-11 10:16:23
|
Hi, Clay <ho...@ho...> wrote: > Hi folks, >=20 > First off, let me say that I'm pretty impressed with what you have started > here. I've been in a similar situation a few times, and decided something > like this was sorely needed, but never had the time to put anything quite= so > coherent together to address it. So, nice work. >=20 > I'm trying to get started small, and have hit a question. >=20 > I'm trying to think of this in terms of having the 'pymodel' file be the > central repository for schema related issues. That seems to be the design > intent anyway -- and really how I would like to do things (central locati= on). First at all, thanks for all the positive feedback ;) About the pymodel: yes, it is the main repository for schema-related issues. However, it is not the only on, esp. when some constraints cannot be easily expressed in a Entity-Relationship model, such as custom validation logic (e.g. do not save any Person whose name is 'Cleese' except if his first name is 'John') which is more easily coded in validation methods in python. >=20 > Suppose I'm going to implement /etc/passwd /etc/group type concepts. This > gives 'user' 'group' and 'usergroup' entities, plus associations. Great. >=20 > using groupID and userID as the primary keys, and the correlation table i= s the > tuple of the two. >=20 Fine. > Heres' my issue. Clearly you want to enforce uniqueness of username (str= ings) > as well as user-ids and integer primary keys. Further, this is something= you > need the DBMS to enforce. Since I'm effectively specifying my schema in > pymodel, it would seem reasonable to be able to add this type of constrai= nt to > that specification. >=20 > Either that, or have a coherent way of maintaining them separatly in a > non-disjoint sort of way. Okay, so you need to be able to say to the DB that these attributes are UNIQUE. Unfortunately, this is not in the framework... yet :) We discussed this some time ago w/ Mario, look here for the corresponding thread: http://sourceforge.net/mailarchive/forum.php?thread_id=3D3575938&forum_id= =3D10674 So (unless you're using sqlite), you can ALTER the correspondig table to make the appropriate attributes UNIQUE, and add some validation logic in your objects making sure that e.g. the login is unique; something like this (untested though): def validateLogin(self, value): "Makes sure that the login is unique before saveChanges() happens" =20=20=20=20=20=20 fs =3D 'login=3D=3D"%s"'%self._login if not self.globalID().isTemporary(): # assuming here that User has a PK named 'id' fs +=3D " AND id!=3D%i" % self.globalID().keyValues()['id'] if self.editingContext().fetchCount('User', fs) !=3D 0: raise Validation.ValidationException Hopefully this makes sense. Back on the functionality, maybe it's time to fill in a RFE and integrate something like this in the framework, what do you think? -- S=E9bastien. >=20 > Looking for either something I've missing in the modelling, or a good > technique to handle this class of problem. >=20 > Thanks, > Clay Hopperdietzel |