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

Queryable with nested structure #1613

Closed
weiwei-lin opened this Issue Apr 5, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@weiwei-lin

weiwei-lin commented Apr 5, 2018

Is there a way to query with nested structure?

#[derive(Queryable)]
struct Foo {
    foo1: i32,
    foo2: i32
}

#[derive(Queryable)]
struct FooBar {
    foo: Foo,
    bar: i32
}

let result = some_table.first::<FooBar>(&conn);

I'm aware that there's QueryableByName, but it seems to require constructing raw query and can't be used with normal queries (e.g. some_table.filter(...).first(&conn)).

@weiznich weiznich added the enhancement label Apr 5, 2018

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 5, 2018

You'll need to nest your columns to match the nesting of your structure. For example:

some_table
    .select(((foo1, foo2), bar))
    .first::<FooBar>(&conn)

@sgrif sgrif closed this Apr 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment