[Maypole] the subtleties of many-to-many stringification

Peter Speltz peterspeltz@yahoo.com
Thu, 2 Dec 2004 14:12:26 -0800 (PST)


--- Seth Gordon <sethg@ropine.com> wrote:

> >>...and everything Just Worked, except for one small detail: the 
> >>"authors" list on the ...library/titles/view/#### page just has the 
> >>authors' names, and not the relationships.
> >>
> > 
> > 
> > Isn't this what you want since you looking at the title already?
> 
> If a book is *written by* Smith and *edited by* Jones, the 
> title_author_rel table will record "by" and "ed.", respectively, in the 
> relationship field.
> 
> When I do my funky dance with JeevesLibrary::TitleAuthorRel::process, a 
> titles/view page will show me
> 
> GREAT AMERICAN NOVEL
> ...
> Authors
> * by Smith
> * ed. Jones
> 
> whereas if I just set up all the relationships in their default 
> fashions, I get
> 
> GREAT AMERICAN NOVEL
> ...
> Authors
> * Smith
> * Jones
> 

I see there are differnt types of authors. I understand the general problem
now. 

> >>(a) why I can't add :Exported methods, dammit
> 
> Aha!  It has to do with the order of module loading.  (All of my model 
> classes are in the JeevesLibrary.pm file, which may be a contributing 
> factor.)  If I wrap the call to JeevesLibrary->setup in a BEGIN block, 
> then I can add the exported methods.
> 
> Now I can implement a search method.....
> 

Cool. Good to know. That must have been what it was for me. I was requireing
modules in wrong order at one time, too. 

> >>(b) if there is a more elegant way to do the same thing
> >>
> > 
> > 
> > Do the object switcheroo in the view Template instead, maybe or just modify
> the
> > template.
> 
> Hmm.  My gut feeling is that this kind of mangling should stay in the 
> model, but I'm not sure I can really justify that as more than a 
> pedantic desire to see how much I can do without touching the default 
> templates.
> 

More trouble than its worth most of the time but i understand.

> I suspect that the OO-philosophically-ideal way to handle this would be 
> to create a new subclass of Class::DBI::Relationship -- perhaps calling 
> it Class::DBI::Relationship::HasAWithQualifier -- and use that to 
> describe the relationship between title_author_rel and authors.
> 

> > Isn't authors an array possibly? I can't see how view template handles that
> as
> > it seems to print the column. Does TT2 automatically print all elements of
> > array? 
> 


> One-to-many relationships in the "view" page are handled by the 
> view_related macro, which the view template calls.
> 

AHAA! That's right. And that's the problem. You need a custom view_related
macro for titles to make it link to authors instead.   Or if you have only one
type of related , authors, then copy it to "view_related_author_title" in the
main macros and adjust it to link to author if looking at a title, and title if
looking at a author.  Then replace "view_related" with
"view_related_author_title" in your titles/view.  

IMO , thats more elegant than overriding process since what you really want is
the author_title relationship and not just author or title in these instances.


=====
pjs


		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail