Skip to content

Commit 11b65ef

Browse files
committed
fix(code): derive "diesel::Identifiable" if struct has a primary-key
fixes Wulf#133
1 parent fe96128 commit 11b65ef

File tree

38 files changed

+39
-37
lines changed

38 files changed

+39
-37
lines changed

src/code.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ impl<'a> Struct<'a> {
213213

214214
if !self.table.foreign_keys.is_empty() {
215215
derives_vec.extend_from_slice(&[derives::ASSOCIATIONS, derives::IDENTIFIABLE]);
216+
} else if !self.table.primary_key_columns.is_empty() {
217+
derives_vec.push(derives::IDENTIFIABLE);
216218
}
217219
}
218220
StructType::Update => {

test/advanced_queries/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(id))]
1212
pub struct Todos {
1313
/// Field representing column `id`

test/autogenerated_all/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(id))]
1212
pub struct Todos {
1313
/// Field representing column `id`

test/autogenerated_attributes/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(id))]
1212
pub struct Todos {
1313
/// Field representing column `id`

test/autogenerated_primary_keys/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(id))]
1212
pub struct Todos {
1313
/// Field representing column `id`

test/cleanup_generated_content/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(id))]
1212
pub struct Todos {
1313
/// Field representing column `id`

test/create_update_bytes_cow/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(data))]
1212
pub struct Todos {
1313
/// Field representing column `data`

test/create_update_bytes_slice/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(data))]
1212
pub struct Todos {
1313
/// Field representing column `data`

test/create_update_str_cow/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(text))]
1212
pub struct Todos {
1313
/// Field representing column `text`

test/create_update_str_str/models/todos/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
88

99
/// Struct representing a row in table `todos`
10-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
10+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Identifiable)]
1111
#[diesel(table_name=todos, primary_key(text))]
1212
pub struct Todos {
1313
/// Field representing column `text`

0 commit comments

Comments
 (0)