Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing of orderBy with joining #125

Open
kevinresol opened this issue Mar 9, 2021 · 2 comments
Open

Typing of orderBy with joining #125

kevinresol opened this issue Mar 9, 2021 · 2 comments

Comments

@kevinresol
Copy link
Member

kevinresol commented Mar 9, 2021

class Main {
	static function main() {
		final db:Db = null;
		db.User.join(db.Post).on(User.id == Post.id).orderBy(f -> [{field: f.User.id, order: Desc}]);
	}
}

@:tables(User, Post)
class Db extends tink.sql.Database {}

typedef User = {
	final id:tink.sql.Types.Id<User>;
}
typedef Post = {
	final id:tink.sql.Types.Id<Post>;
}

errors with

src/Main.hx:12: characters 13-22 : error: { User : Table0_Result, Post : Table1_Result } has no field id
src/Main.hx:12: characters 13-22 :  have: tink.sql.Field<..., { id }>
src/Main.hx:12: characters 13-22 :  want: tink.sql.Field<..., { User, Post }>
src/Main.hx:12: characters 13-22 : For function argument 'orderBy'

This is basically just a typing issue caused by the wrong Owner in Field. With cast f.User.id it runs fine at runtime because it is merely an Expr

@kevinresol
Copy link
Member Author

Same for groupBy:

db.User.join(db.Post).on(User.id == Post.id).groupBy(f -> [f.User.id]);

@benmerckx
Copy link
Member

Not completely related, but I had this api idea:

abstract Field(...) {
  public function asc()
    return {field: this, order: Asc}
  public function desc()
    return {field: this, order: Desc}
}
...orderBy(f -> [f.User.id.desc()])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants