On Mon, Mar 21, 2016 at 5:21 PM, <c.bu...@posteo.jp> wrote:

> Hi Michal
>
> >     q.join(ReferenceAuthor, ReferenceAuthor.c.Index == 0)
>
> Ah, of course! Thank you very much!
>
> But... ;)
>
> This Python code
>
>          return self.session.query(Reference) \
>                  .filter_by(_mark = False) \
>                  .join(Periodical) \
>                  .join(ReferenceAuthor,
>                        ReferenceAuthor.c.Index==0) \
>                  .join(Person) \
>                  .order_by(Periodical._name) \
>                  .order_by(Person._lastname) \
>                  .all()
>
>
>
> The SQL echoed looks ok:
>
> SELECT "Reference"."ID" AS "Reference_ID",
>        "Reference"."HasLabel" AS "Reference_HasLabel",
>        "Reference"."PeriodicalID" AS "Reference_PeriodicalID"
> FROM "Reference"
> JOIN "Periodical"
>         ON "Periodical"."ID" = "Reference"."PeriodicalID"
> JOIN "ReferenceAuthor"
>         ON "ReferenceAuthor"."Index" = ?
> JOIN "Person"
>         ON "Person"."ID" = "ReferenceAuthor"."PersonID"
> WHERE "Reference"."HasLabel" = 0
> ORDER BY "Periodical"."Name",
>          "Person"."LastName"
>
> But result doesn't looks like that it is secondary sorted by first
> persons lastname. See as an example one "Periodical._name" (Bmc
> Geriatrics) and the first persons lastname of 8 References.
>
> Bmc Geriatrics
>   Dapp
>   Tuntland
>   Hsu
>   van der Elst
>   Khatib
>   Hermans
>   van Buul
>   Lichtner
>

You are missing the join condition between ReferenceAuthor and Reference.
You probably want something like this:

join(ReferenceAuthor,
     and_(ReferenceAuthor.c.ReferenceId == Reference.ID),
          ReferenceAuthor.c.Index == 0))

Simon

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to