"goff" <[EMAIL PROTECTED]> writes:
Greetings,
I just started to work with TurboGears (the book brought me in, you
know), and I started by writing my own test cases to the identity
classes that 'tg-admin quickstart -i' wrote into my model.py. Now one
of these tests is failing, and I just cant understand why.
Take this case (entered into 'tg-admin shell':
user = User( user_name="me", display_name="myself",
email_address="[EMAIL PROTECTED]", password="" )
group1 = Group ( group_name="group1", display_name="The First Group" )
group2 = Group ( group_name="group2", display_name="The Second Group" )
user.addGroup(group1)
user.addGroup(group2)
assert len(user.groups) == 2
Group.delete(group1.id)
hub.commit()
assert len(user.groups) == 1
Traceback (most recent call last):
File "<console>", line 1, in ?
File "<string>", line 1, in <lambda>
File "/usr/lib/python2.4/site-packages/sqlobject/joins.py", line 207,
in performJoin
return self._applyOrderBy([self.otherClass.get(id, conn) for (id,)
in ids if id is not None], self.otherClass)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 913,
in get
val._init(id, connection, selectResults)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 958,
in _init
raise SQLObjectNotFound, "The object %s by the ID %s does not
exist" % (self.__class__.__name__, self.id)
SQLObjectNotFound: The object Group by the ID 1 does not exist
Now what went wrong? Could somebody please enlighten me on this?
I dunno how is your SQL knowledge, but if you don't understand the answer ask
again ;-)
What happens is that the relationships defined by SO for these classes don't
have any concern with maintaining referential integrity.
The correct would be defining a FK and doing something like ON DELETE RESTRICT
(it is possible to code that with SO). Unfortunately, the auto-mapping done
here doesn't do that (you could do that by hand later, but the auto-creation
mechanism won't do it for you).
So, what happened is that you did was:
1. create a user
2. create two groups
3. assign those two groups to the user
4. (intentionally ommited)
5. delete one of the groups
6. ask the user what groups it is associated with
7. count the answer from the user
Item 4 should be "remove the association of the soon to be deleted group with
the user". It could be done automatically on 5 (ON DELETE CASCADE) though,
but as I said, it isn't done by SO.
Be seeing you,
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---