angel-dart-archive / orm

moved to angel-dart/angel/packages/orm

Home Page:https://github.com/angel-dart/angel/tree/master/packages/orm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Order by a foreign table column

carmas123 opened this issue · comments

*This issue was automatically moved to: angel-dart/angel#218.

Have you tried Query.orderBy (or maybe the name is sortBy, I forgot)?

Yes I try it but when I try to sort a foreign key I need to specify the table alias.
When the orm generate query with builder it assign a dynamic query name: a0, a1, a2...aN
and then I cannot specify the column name with an alias.
For example:
Table A => (id, name, col1, col2)
Table B => (id, table_a_id, name, col1, col2)

Now when join table A and table B they have some columns name, I need to sort by column "name" of table B.

This is actually a bit more complicated than it seems at first glance, since the names a0, a1, etc. are picked at runtime, not during codegen.

Have you tried orderBy('b.name')? The string given is passed right into the SQL query, so you could really put anything there.

If that doesn't work, then I had may have to add a feature to JoinBuilder that lets you explicitly specify the name for a join, and then modify the code generator to use this.