Skip to content

Commit

Permalink
Merge pull request diesel-rs#3782 from snf/queryable_multi_table
Browse files Browse the repository at this point in the history
allowing Queryable to be used with multiple table names
  • Loading branch information
weiznich authored Sep 8, 2023
2 parents fed0407 + 2c5e6a8 commit ac0b075
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,3 @@ error: expected a single table name attribute
|
52 | #[diesel(table_name = users_)]
| ^^^^^^^^^^

error: expected a single table name attribute
note: remove this attribute
--> tests/fail/derive/multiple_table_names.rs:59:30
|
59 | #[diesel(table_name = users, table_name = users_)]
| ^^^^^^^^^^
2 changes: 1 addition & 1 deletion diesel_derives/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::model::Model;
use crate::util::wrap_in_dummy_mod;

pub fn derive(item: DeriveInput) -> Result<TokenStream> {
let model = Model::from_item(&item, false, false)?;
let model = Model::from_item(&item, false, true)?;

let struct_name = &item.ident;
let field_ty = &model
Expand Down
24 changes: 24 additions & 0 deletions diesel_derives/tests/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ fn tuple_struct_without_column_name_annotations() {
let data = select(sql::<(Integer, Integer)>("1, 2")).get_result(conn);
assert_eq!(Ok(MyStruct(1, 2)), data);
}

#[test]
fn multiple_tables() {
#[derive(Debug, Clone, PartialEq, Eq, Queryable)]
#[diesel(table_name = users)]
#[diesel(table_name = users_)]
struct NewUser {
name: String,
hair_color: String,
}

let conn = &mut connection();
let data = select(sql::<(diesel::sql_types::Text, diesel::sql_types::Text)>(
"'red', 'red'",
))
.get_result(conn);
assert_eq!(
Ok(NewUser {
name: "red".to_string(),
hair_color: "red".to_string()
}),
data
);
}

0 comments on commit ac0b075

Please sign in to comment.