[Haskell-cafe] ORM for haskell?

Mads Lindstrøm mads_lindstroem at yahoo.dk
Tue Jun 30 17:34:01 EDT 2009

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. 


Mads Lindstrøm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090630/b01b42a9/attachment.bin

More information about the Haskell-Cafe mailing list