diesel-rs/diesel

Cannot use multiple table_name for Insertable when also deriving Queryable

Mossop opened this issue · 1 comments

Setup

Versions

  • Rust: 1.75.0
  • Diesel: 2.1.4
  • Database: N/A
  • Operating System; macOS

Feature Flags

  • diesel: default

Problem Description

#3535 added support for multiple table_name attributes when deriving Insertable but this breaks if you also attempt to derive Queryable.

What are you trying to accomplish?

I have two tables which share a common subset of columns so in my structs I want to split those columns into their own struct as it will allow me to share some behaviours. To do this I make all the structs derive Insertable and on the split out struct I set multiple table_name attributes and use the embed attribute. But I also want to be able to query these by making the structs Queryable (I have to manually list the columns rather than using all_columns but some macros take care of that) and as soon as I do the code fails to compile.

What is the expected output?

The code should compile.

What is the actual output?

error: expected a single table name attribute

Are you seeing any additional errors?

No

Steps to reproduce

The error reproduces with this simple file:

use diesel::{Insertable, Queryable};

diesel::table! {
    user1 (id) {
        id -> Varchar,
        name -> Text,
    }
}

diesel::table! {
    user2 (id) {
        id -> Varchar,
        name -> Text,
    }
}

#[derive(Queryable, Insertable)]
#[diesel(table_name = user1, table_name = user2)]
pub struct User {
    id: String,
    name: String,
}

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

That's a duplicate of #3782.