Open mastfissh opened 5 years ago
I have the feeling we're already really close. This almost works
#[test]
fn test_advanced_query() {
let db = connect_to_db();
let user = UserFactory::default().insert(&db);
let query = follows::table
.inner_join(users::table.on(users::id.eq(follows::followee_id)))
.filter(
follows::followee_type
.eq("User")
.and(follows::follower_id.eq(user.id))
.and(follows::unfollowed_at.is_null()),
)
.select(users::all_columns);
let query = KeysetPaginated {
query,
order: (users::firstname, users::lastname),
// TODO: This should be a real cursor so an id from a previous query
filter: users::id.eq(user.id),
page_size: 20,
};
let users = query.load::<User>(&db).unwrap();
assert!(users.is_empty());
}
It fails saying that HasTable
isn't implemented for a join query
212 | let users = query.load::<User>(&db).unwrap();
| ^^^^ the trait `diesel::associations::HasTable` is not implemented for `diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<test::schema::follows::table, test::schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<test::schema::users::columns::id, test::schema::follows::columns::followee_id>>`
I bet there is way around that.
I think it's good to have a goal, so this should be able to handle a query like: