Mark,
I am facing a similar situation and was wondering how would you recommend
writing the hasTheme and getTheme method on a book decorator?

Thanks in advance

Qasim

On Tue, Oct 28, 2008 at 5:22 PM, Mark Mandel <[EMAIL PROTECTED]> wrote:

>
> Stephen,
>
> You're approach is totally correct - there is nothing wrong with it.
>
> With an approach like this, I tend to write some decorator code to
> make my life super simple, so I can write something like:
>
> locals.tTheme = getContentServer().getByID("stories.theme",locals.themeID);
>
> if(book.hasThere(locals.tTheme)) //decorator method
> {
>  locals.tBookTheme = boom.getTheme(locals.tTheme) //decorator method
> }
> else
> {
>   locals.tBookTheme = getContentServer().getNew("stories.booktheme");
>    locals.tBookTheme.setParentBook(bookClone);
>   locals.tBookTheme.setParentTheme(locals.tTheme);
> }
>
> locals.tBookTheme.setStarRating(locals.thisFieldValue);
>
> getContentServer().save(locals.tBookTheme);
>
> That make sense?
>
> ... on a side note, I'm almost tempted to integrate a Closure library
> to make writing this sort of looping find/sort that much easier.
>
> Mark
>
> On Wed, Oct 29, 2008 at 1:17 AM, Stephen Moretti
> <[EMAIL PROTECTED]> wrote:
> > I really don't understand why, but there is something about composite
> keys
> > that just isn't sinking in and I don't understand why its not working.
> >
> > I have the following objects in a package called stories:
> > <object name="book" table="book">
> > <id name="ID" column="BookID" type="numeric"/>
> > <property name="Title" type="string"/>
> > <property name="Summary" type="string"/>
> > <property name="Author" type="string"/>
> > <property name="Illustrator" type="string" nullable="true"/>
> > <property name="DateCreated" type="date"/>
> > <property name="DatePublished" type="date" nullable="true"/>
> > <property name="BookImage" type="string"/>
> > <onetomany name="Theme" lazy="true">
> > <link to="stories.booktheme" column="BookID" />
> > <collection type="array">
> > </collection>
> > </onetomany>
> > </object>
> > <object name="booktheme" table="booktheme">
> > <compositeid>
> > <parentonetomany class="stories.book" />
> > <parentonetomany class="stories.theme" />
> > </compositeid>
> > <property name="StarRating" type="numeric" />
> > </object>
> > <object name="theme" table="theme">
> > <id name="ID" column="ThemeID" type="numeric"/>
> > <property name="Title" type="string"/>
> > <property name="UniqueName" type="string"/>
> > <onetomany name="Book" lazy="true">
> > <link to="stories.booktheme" column="ThemeID" />
> > <collection type="array">
> > </collection>
> > </onetomany>
> > </object>
> > I can now update book properties and add new Themes with star ratings to
> > books, but I'm a little uncomfortable about the adding themes to a new
> book
> > and a unsure about updating themes on an existing book.
> > The code I have for adding themes to a book is as follows :
> >>
> >> locals.tBookTheme = getContentServer().getNew("stories.booktheme");
> >>
> >> locals.themeID = ListLast(locals.thisField,"_");
> >>
> >> locals.tTheme =
> >> getContentServer().getByID("stories.theme",locals.themeID);
> >>
> >> locals.tBookTheme.setParentBook(bookClone);
> >>
> >> locals.tBookTheme.setParentTheme(locals.tTheme);
> >>
> >> locals.tBookTheme.setStarRating(locals.thisFieldValue);
> >>
> >> getContentServer().save(locals.tBookTheme);
> >
> >
> > getContentServer() basically equates to being Transfer, but with added
> > extras.
> > The star rating is held in a form field called starrating_{themeid}, so I
> > get the themeID from the form field name and then get a theme TO for that
> > themeID. The current book, bookClone, can either be a clone of an
> existing
> > book or a new book TO.
> > What I'm uncomfortable with when adding themes to a new book is that at
> the
> > point that themes and their star ratings are being added to a book TO
> there
> > is no bookID, so if I save this book theme TO there won't be a bookID or
> the
> > BookID will be zero. However, if I don't save the book theme and its star
> > rating I'm not sure how I can add the book theme to a book TO so that I
> can
> > then run a casadeSave() against my book TO.
> > If I try to update my array of book theme and their star ratings I get a
> > problem that having emptied the theme array on my book TO I have to
> > cascadeSave() the whole book TO.  This is so that when I save a book
> theme I
> > don't get a duplicate key error. I don't really like saving the whole
> record
> > at this point.  I only want to save my object to the database when
> > everything is ready and not before.
> > If you're wondering why I'm emptying the theme array, its because there's
> > really not that many themes.  There's more processing involved in
> checking
> > to see if an individual theme currently exists adding it and deleting any
> > themes that shouldn't be in there any more than to simply dump the lot
> and
> > reinsert the records.
> > The problem boils down to - how do I add child book themes to a book TO
> > without saving the book TO or the booktheme TO?
> > Does that make any sense?  Am I going about this the wrong way?  What am
> I
> > missing?
> > Thanks for your help
> > Stephen
> >
> >
> > >
> >
>
>
>
> --
> E: [EMAIL PROTECTED]
> W: www.compoundtheory.com
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" 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/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to