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:

class Story(SQLObject):
    """
    Contains the first page, and meta about a story.
    """
    title=UnicodeCol(alternateID=True, length=100)
    summary=UnicodeCol()
    pages=MultipleJoin('Page')
    first_page=ForeignKey('Page', default=None)

class Page(SQLObject):
    """
    A page in a story.
    """
    short_title=UnicodeCol(alternateID=True, length=20)
    text=UnicodeCol()
    story=ForeignKey('Story', cascade=True, default=None)
    choices=MultipleJoin('Choice')

class Choice(SQLObject):
    """
    A choice for a page in a story.
    """
    text=UnicodeCol()
    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!

Mike


On Sun, Jan 25, 2009 at 3:01 PM, Oleg Broytmann <phd@phd.pp.ru> wrote:
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)
>     summary=UnicodeCol()
>     pages=MultipleJoin('Page')
>     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)
>     text=UnicodeCol()
>     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
> (using Turbogears, so automatic via tg-admin sql create), I get told I have
> a circular dependency between Page and Story.  Do I really?i

  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
puts stdout/stderr).

 1/QueryR  :  CREATE TABLE story (
   id SERIAL PRIMARY KEY,
   title VARCHAR(100) NOT NULL UNIQUE,
   summary TEXT,
   first_page_id INT
)
 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.

> Is this
> something I have to worry about?

  No, at least not with SQLObject - don't know about TG. There is a way in
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.
--
    Oleg Broytmann            http://phd.pp.ru/            phd@phd.pp.ru
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss