How to join for where clause but not select a table

I’m trying to do a join on a table so that I can filter records but not actually selecting from that table. Here’s the example where it’s still selecting from the joined table. I assume you can manually specify the select using tuples but is there a way to do this using a Queryable struct instead?

  let (existing_excerpt, _) = source_items::table
    .inner_join(sources::table)
    .filter(source_items::id.eq(json.original_excerpt_id))
    .filter(sources::user_id.eq(jwt.user_id))
    .first::<(SourceItem, Source)>(&db.0)
    .map_err(PostError::LoadSourceID)?;

Any advice? Thanks.

Just use a explicit select clause to specify which columns you want to select. Those need to match your struct that implements Queryable. If you want to select all columns of a given table you can do something like .select((sources::column_a, sources_column_b, …)) or .select(sources::all_columns)

1 Like