:(

OK, sorry about the obfuscated names.  Don't know what came over me.  I
have a CMS site, with advertising.

I have:

class Picture(SQLObject):
        producer = ForeignKey('Producer')
        image_categories = SQLRelatedJoin('Image_category')

class Ad(SQLObject):
        producer_categories = SQLRelatedJoin('Producer_category')
        image_categories = SQLRelatedJoin('Image_category')

class Producer(SQLObject):
        producer_category = ForeignKey('Producer_category')

class Producer_category(SQLObject):
        producers = SQLMultipleJoin('Producer')
        ads = SQLRelatedJoin('Ad')

class Image_category(SQLObject):
        ads = SQLRelatedJoin('Ad')
        pictures = SQLRelatedJoin('Picture')

Say I want to display a picture, p = Picture() on a page.  I need to
find an Ad to display with it.  The rules for ad selection is that it
needs to have the producer_category which encompasses the picture in is
producer_categories field.  And that its image_categories and the
picture's image_categories need to have at least one element in common.

I know I could use SQLBuilder to select what I need, but something tells
me I'm not doing this in the most elegant manner possible.

Suggestions, anyone?

Thanks,

Stuart


On Mon, 2006-11-06 at 09:45 +0000, Jorge Vargas wrote:
> I think either you have a very very complex project or your not using
> the object relational mapper right. SQLObject are not tables.
> 
> can you post a "real" example maybe what you need is a simplier Model layer.
> 
> but I can tell you with all those RelatedJoin it can very very slow.
> 
> On 11/6/06, Stuart Clarke <[EMAIL PROTECTED]> wrote:
> >
> > Sorry, I mis-wrote the problem setup.  It should be:
> >
> > class A(SQLObject):
> >         foo = SQLRelatedJoin('E')
> >         bar = ForeignKey('C')
> >
> > class B(SQLObject):
> >         smell = SQLRelatedJoin('E')
> >         mummy = SQLRelatedJoin('D')
> >
> > class C(SQLObject):
> >         fine = ForeignKey('D')
> >
> > class D(SQLObject):
> >         hair = SQLMultipleJoin('C')
> >         bees = SQLRelatedJoin('B')
> >
> > class E(SQLObject):
> >         moo = SQLRelatedJoin('A')
> >         itch = SQLRelatedJoin('B')
> >
> > a = A()
> >
> >
> > On Mon, 2006-11-06 at 19:24 +1000, Stuart Clarke wrote:
> > > Thanks for the reply, but the solution doesn't work for me.
> > >
> > > The problem I posted was actually part of a wider one.  Details:
> > >
> > > class A(SQLObject):
> > >       foo = SQLRelatedJoin('B')
> > >       bar = ForeignKey('C')
> > >
> > > class B(SQLObject):
> > >       smell = SQLRelatedJoin('B')
> > >       mummy = SQLRelatedJoin('D')
> > >
> > > class C(SQLObject):
> > >       fine = ForeignKey('D')
> > >
> > > class D(SQLObject):
> > >       hair = SQLMultipleJoin('C')
> > >       bees = SQLRelatedJoin('B')
> > >
> > > a = A()
> > >
> > > OK, my problem is that I want to find all b = B(), such that a.bar.fine
> > > is in b.mummy AND the intersection of a.foo and b.smell is not an empty
> > > set.
> > >
> > > So, I can get b_global = a.bar.fine.bees which gives me a SelectResults
> > > of B instances that contains every one I could be interested in, plus
> > > some more.
> > >
> > > I need to select amongst those.  Something along these lines:
> > >
> > > for my_foo in a.foo:
> > >       b_subset = b_global.filter(my_foo is in B.smell)
> > >
> > > I don't mind having the separate b_subsets at this point, although if I
> > > could aggregate them and specify that each b in b_subsets_aggregate be
> > > unique, then that would be even better.
> > >
> > > So, who's got the chops to help me with this monster? :-)
> > >
> > >
> > > On Mon, 2006-11-06 at 08:40 +0000, [EMAIL PROTECTED] wrote:
> > > > It sounds like what you want to do is this:
> > > >
> > > > class A(SQLObject):
> > > >     foo = RelatedJoin('B')
> > > >
> > > > class B(SQLObject):
> > > >     bar = RelatedJoin('A')
> > > >
> > > > It's a good idea to keep references in both objects.
> > > >
> > > > I believe the join you want goes like this:
> > > >
> > > > A.select(A.q.fooID==b.id)
> > > >
> > > > See:
> > > > http://www.sqlobject.org/SQLObject.html#selecting-multiple-objects
> > > >
> > > > Hope that helps!
> > > >
> > > > -David
> > > >
> > > >
> > > > >
> > > >
> > --
> > Stuart Clarke <[EMAIL PROTECTED]>
> >
> >
> > >
> >
> 
> > 
> 
-- 
Stuart Clarke <[EMAIL PROTECTED]>


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

Reply via email to