Perhaps just add a boolean field in the chapter table: is_first ... or
something to that effect??
On saving an un-flagged chapter you can always check whether any other
chapters for the story have been flagged as first; if not auto flag
the one being saved.
If a subsequent chapter (marked as first) is saved then set all others
to false.

Not perfect but just a thought...


On Apr 8, 8:05 am, guruyaya <[email protected]> wrote:
> I wanted something more generic to work with, for future uses. But I
> guess you're right.
>
> On Apr 7, 11:42 pm, villas <[email protected]> wrote:
>
>
>
>
>
>
>
> > Why not simply write an onvalidation function?
>
> > When you save a record with form accepts this would check to ensure
> > that you only have one first_chapter for that story_id.
>
> > On Apr 6, 9:29 pm,guruyaya<[email protected]> wrote:
>
> > > Here's a simplified version of a model I'm working on:
>
> > > db.define_table('story',
> > >     Field('title'),
> > >     Field('description', 'text'),
> > >     Field('first_chapter', db.chapter)
> > > )
>
> > > db.define_table('chapter',
> > >     Field('title'),
> > >     Field('tale', 'text'),
> > >     Field('story_id',db.story)
> > > )
>
> > > As you can imagine, I have a problem here. I cannot reference the
> > > first chapter in the story table, because chapter is not yet defined,
> > > but I cannot write thetablesbackwards, because story won't be
> > > defined.
> > > I was wondering if there's any way of doing this elegantly, or I'll
> > > just have to count on the first chapter written of any story - to be
> > > the first chapter.
> > > Thanks in advance
> > > Yaya

Reply via email to