Discussion:
[Modeling-users] Intro/Question
Clay
2004-05-08 12:36:00 UTC
Permalink
Hi folks,

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.

I'm trying to get started small, and have hit a question.

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 location).

Suppose I'm going to implement /etc/passwd /etc/group type concepts.
This gives 'user' 'group' and 'usergroup' entities, plus associations.
Great.

using groupID and userID as the primary keys, and the correlation table
is the tuple of the two.

Heres' my issue. Clearly you want to enforce uniqueness of username
(strings) 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 constraint to that specification.

Either that, or have a coherent way of maintaining them separatly in a
non-disjoint sort of way.

Looking for either something I've missing in the modelling, or a good
technique to handle this class of problem.

Thanks,
Clay Hopperdietzel
Sebastien Bigaret
2004-05-11 08:17:06 UTC
Permalink
Hi,
Post by Clay
Hi folks,
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.
I'm trying to get started small, and have hit a question.
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 location).
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.
Post by Clay
Suppose I'm going to implement /etc/passwd /etc/group type concepts. This
gives 'user' 'group' and 'usergroup' entities, plus associations. Great.
using groupID and userID as the primary keys, and the correlation table is the
tuple of the two.
Fine.
Post by Clay
Heres' my issue. Clearly you want to enforce uniqueness of username (strings)
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 constraint to
that specification.
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=3575938&forum_id=10674

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"

fs = 'login=="%s"'%self._login

if not self.globalID().isTemporary():
# assuming here that User has a PK named 'id'
fs += " AND id!=%i" % self.globalID().keyValues()['id']

if self.editingContext().fetchCount('User', fs) != 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ébastien.
Post by Clay
Looking for either something I've missing in the modelling, or a good
technique to handle this class of problem.
Thanks,
Clay Hopperdietzel
Loading...