Hi Marc

> Example why it matters:
> schools - 1:n - teachers - 1:n - pupils
> 
> If you want to list all schools which have a pupil with age > 3 you'd
> write an sql query like this:
> 
>   SELECT dictinct * FROM schools as s JOIN teachers t ON (t.school_id = s.id) 
> JOIN pupils as p ON (p.teacher_id = t.id) WHERE p.age > 3
> 
>   in SQLAlchemy it looks like this:
>   
> session.query(School).join(School.teachers).join(Teacher.pupils).filter(Pupil.age
>  > 3).all()
> 
>   difference? Because SQLAlchemy knows about the relations you don't have
>   to remember alias names. So there is no chance to get that wrong.

I do not get this explanation, could you expand? I would have thought it
should be: "difference? Because SQLAlchemy knows about the relationships
(not relations, but relation_ships_), it do not have to explicitly join
on foreign keys.".

Actually SQL has natural joins, where you can do without explicit join
conditions. Unfortunately, natural joins seems like they were explicitly
designed to create trouble. It would be nice if "they" fixed SQL to
consider relationships. 


Greetings,

Mads Lindstrøm

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to