On Feb 11, 2013, at 6:10 PM, Matthew Rich <matt...@matthewrich.com> wrote:

> On Monday, February 11, 2013 5:00:50 PM UTC-6, Michael Bayer wrote:
> 
> should be easy enough to create those joins automatically using the 
> relationship: 
> 
> query(School.id, 
> func.count(Coordinator.id)).join(School.coordinators).group_by(School.id).having(func.count(Coordinator.id)
>  > 1) 
> 
> 
> or you could join() explicitly with a separate target/ON clause, shouldn't be 
> necessary though.
> 
> Thanks for your reply Mike. I tried exactly that but I get: 
> 
> AttributeError: type object 'School' has no attribute 'coordinators'
> 
> So I went ahead and got rid of the backref from the relationship defined in 
> Coordinator and explicitly added the "coordinators" relationship on School 
> and now it works. Worth a ticket?

no…. if you want two relationships, link them with back_populates.  If you want 
to go back to using backref (easier), if your query is the absolutely first 
thing you're doing, here are three workarounds:

        1. call configure_mappers() explicitly when your program starts, after 
the mappings are imported and before you run your query.

        2. use a string to join, so that you don't need that symbol until the 
Query starts up and configures the mappings:

        query(…).join("coordinators").group_by(…)

        3. run query() and then the join() in a second step, so that query() 
has a chance to configure the mappings:

        q = query(…)
        q = q.join(School.coordinators)


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to