Aha! I see where you're headed with this. As it turns out, the pages for a story truly are unordered. The purpose here is to write a "Choose your own adventure" style of story. I only included info on the problem I was having. The missing piece of the model allows for a page to have a number of choices that link to another page. So, the full (relevant) model is:
Contains the first page, and meta about a story.
A page in a story.
story=ForeignKey('Story', cascade=True, default=None)
A choice for a page in a story.
page=ForeignKey('Page', cascade=True, default=None)
choice_page=ForeignKey('Page', cascade='null', default=None)
Did this answer the "bigger problem"? Thanks for the help!
...On Sat, Jan 24, 2009 at 06:07:12PM -0500, Michael LeSauvage wrote:
> All help appreciated. The following is my data model. The idea here is
> that a *Story* can be comprised of many pages. One, and only one, of those
> pages may be the starting point of the story. I attempted to model this via
> a MultipleJoin (pages in a story), a ForeignKey(to map to a single page for
> a story), and a link back from the Page using a ForeignKey.
> class Story(SQLObject):
> Contains the first page, and meta about a story.
> title=UnicodeCol(alternateID=True, length=100)
> first_page=ForeignKey('Page', default=None) #without this, model works
> #alternate, but feels like a kludge: first_page=IntCol(default=0)
> class Page(SQLObject):
> A page in a story.
> short_title=UnicodeCol(alternateID=True, length=20)
> story=ForeignKey('Story', default=None)
> I clearly don't understand what's going on under the hood.
> Heh. OK, more detail. The *problem* is that when I generate the database> a circular dependency between Page and Story. Do I really?i
> (using Turbogears, so automatic via tg-admin sql create), I get told I have
Yes, you have. It is easy to see what is going on if you add '?debug=1'
to the database URI and watch the output (or logs - I don't know where TG
1/QueryR : CREATE TABLE story (
id SERIAL PRIMARY KEY,
title VARCHAR(100) NOT NULL UNIQUE,
1/COMMIT : auto
1/QueryR : ALTER TABLE story ADD CONSTRAINT first_page_id_exists FOREIGN
KEY (first_page_id) REFERENCES page (id)
1/COMMIT : auto
See? SQLObject created one table and tried to create a constraint - and
failed because there is no the other table.
No, at least not with SQLObject - don't know about TG. There is a way in
> Is this
> something I have to worry about?
SQLObject to defer constraint creation until all tables are created. I will
show you the way. Later.
Now I see a problem in your model, and I consider the problem as bigger
problem. After we fix the bigger problem it is possible the problem you
have encountered becomes irrelevant. That's why I said 'later'.
Let me start with a question that is actually a hint. Is you Story an
*unordered* collection of Pages?! Before answering please remember SQL
doesn't guarantee any order of rows until a query specifies an order.
Oleg Broytmann http://phd.pp.ru/ email@example.com
Programmers don't die, they just GOSUB without RETURN.
This SF.net email is sponsored by:
SourceForge wants to tell your story.
sqlobject-discuss mailing list