Doh, must be tired.  That works.... cool... finally have my first
SQLAlchemy ORM stuff working.  Thanks...


Is it best practice to move the joins into the filter(where) clause
like this, (in this case channelbuild.build_id is FK to the PK
build.id)?

I tried putting the join inside the distinct - like this:
  distinct( joined_builds.device_id )

But the join itself doesn't have the .device_id
  although when I call .first() on it, it outputs
     MappedBackfill_build
(id=221847,game_id=711,device_id=8443,in_icp=False)

  - OTOH I may be worrying about nothing, should I just move all my
joins to the filter clause when I convert my more complex queries ?



Cheers,
Stuart


On Apr 1, 4:48 pm, "Michael Bayer" <[email protected]> wrote:
> Stu.Axon wrote:
>
> > I tried this
> > session\
> >     .query(func.count(distinct(build.device_id)))\
> >     .filter(channelbuild.channel_id == 9)\
> >     .filter(build.in_icp == False)\
> >     .scalar()
>
> > It generated this sql:
>
> > SELECT
> >     count(DISTINCT backfill_build.device_id)
> > AS
> >     count_1
> > FROM
> >     backfill_build, backfill_channelbuild
> > WHERE
> >     backfill_channelbuild.channel_id = %(channel_id_1)s
> > AND
> >     backfill_build.in_icp = %(in_icp_1)s
> > -- {'in_icp_1': False, 'channel_id_1': 9}
>
> if you are querying from two tables, those tables must be joined together
> somehow else you'll get a cartesian product.  you're looking to add
> backfill_build.some_id=backfill_channelbuild.some_other_id here.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to