De: Paul McNett <[EMAIL PROTECTED]>
Data: Terça-Feira, 24 de Abril de 2007, 18:10
Assunto: Re: [dabo-users] Strategies for populating controls with data  from 
many-to-many       relation

> Hi Miguel,
> 
> I'll try to help you out with this over the next day or so (really 
> busy 
> now) but scroll down because I do answer a couple of your specific 
> questions.
> 
> 
> > I'm wondering what would be the best strategy (and alternatives) 
> to populate a control with data from a many-2-many relation.
> > 
> > Here's the setup (You can find this Demo In Progress in the Wiki 
> under "Demos in Progress":
> > book.book_id (table.table_pk)
> > bookauthor (link table, fields: bookauthor_id, book_id, author_id)
> > author.author_id (table.table_pk)
> > 
> > 
> > Objective:
> > Populate a dListBox in a form where the primary bizobj 
> datasource is book. Everytime one changes book the dListBox gets 
> populated with the name of the related authors. I've read the 
> WikiPage "How To Populate and Use List Controls" but I can't get 
> much from it for this particular cross-table dynamic context.
> > 
> > 1 - My feeling is that dabo can take care of this for me (is 
> this true?).
> > 
> > Do I accomplish this by chaining bizobjs? I mean make bookBizobj 
> parent of BookAuthorBizobj and BookAuthorBizobj parent of 
> RelatedAuthorBizobj! I've tryed this approach without any 
> complaints from Dabo (no exceptions raised), but I'm unable to 
> figure out to populate the dListBox. The code in the WikiPage 
> reflects these changes.
> 
> For 1:M joins, bizobj chaining works very well because Dabo 
> handles 
> requerying the children automatically. M:M joins should work as 
> well 
> chained like this but I haven't done it that way in the past.

I have no special requisite to make it in one way or another. Actually I would 
prefer the approach that is most maintainable in growing projects that could 
turn out quite large. This is my favorite way of coding anything - sounds like 
I'm a paper-plane chasing perfectionist :-( !!!

> > My difficulty comes from the fact that I have to bizobjs with 
> the same DataSource.
> >   * AuthorBizobj - used to populate the Authors Grid on page two 
> (working like a charm - txs guys ;-)
> >   * relatedAuthorBizobj - to be used to populate the dListBox 
> (as per above)
> 
> self.Form.getBizobj("author") will return your authorbizobj 
> because 
> you've done self.Form.addBizobj(bizAuthor). Keep a separate 
> reference to 
> relatedAuthorBizobj without doing Form.addBizobj() with it.

Usually Mickey Mouse solutions are amongst the best. Txs for the tip.

> > 2 - If dabo can't do this for me what would be the soundest 
> approach?>   * Should bizobjs be used?
> 
> Dabo doesn't offer full-automatic handling of M:M joins, but it 
> isn't difficult once you've done it once. The ListBox needs a DataField 
> to save to (this would be a field in the join table) as well as a 
> source of values to list (this would be your authorBizobj.author_name 
> field). 
> Again, I'll get back with concrete examples as soon as possible.
> 
> Yes, bizobjs should definitely be used.

I see what you mean. I'll be saving book_id's and author_id's and displaying 
related authorname's.

> > BTW: Is there a way to get a bizobj or a dataset with fields 
> from two tables?
> 
> Yes, although it won't save changed fields from other than the 
> main 
> table (the DataSource one). Just write your sql appropriately:
> 
> biz.UserSQL = """
> select book.name as book_name,
>        author.name as author_name
>   from book
>   left join author_book
>     on author_book.book_id = book.id
>   left join author
>     on author.id = author_book.author_id
> """
> 
> -- 
> pkm ~ http://paulmcnett.com

Sure. I was wondering more in the direction of an updatable view.

Thank you very much for the time and tips. I have plenty of exploring to do now.
Thanks again,
Miguel

_______________________________________________________________________________________
Aqueca o seu Inverno com o credito pronto a usar!
Saiba mais em http://www.iol.pt/correio/rodape.php?dst=0701181



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]

Reply via email to