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.
> 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.
> 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.
> 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
_______________________________________________
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]