adwhit/diesel-derive-enum

no `CategoryEnumMapping` in `schema`

Closed this issue · 2 comments

Hello,

Quick disclaimer, i'm fairly new to rust :).

I've been toying around with this library for hours now, and i simply can't get it to work.

I created the following enum. (Postgres)

CREATE TYPE category_enum AS ENUM ('none', 'pug', 'scrim', 'official');

Created my enum in my models.rs


#[derive(DbEnum)]
pub enum CategoryEnum {
  None,
  Pug,
  Scrim,
  Official
}

#[derive(Insertable, Debug)]
#[table_name="delta_stats"]
pub struct NewDeltaStat {
  pub value: f64,
  pub category: CategoryEnum
}

And applied it to my schema

table! {
    use diesel::sql_types::*;
    use super::CategoryEnumMapping;

    delta_stats (id) {
        id -> Int8,
        value -> Float8,
        category -> CategoryEnumMapping,
    }
}

But i get the following error when i try to compile it

error[E0432]: unresolved import `super::CategoryEnumMapping`
 --> src/schema.rs:3:9
  |
3 |     use super::CategoryEnumMapping;
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `CategoryEnumMapping` in `schema`

What am i doing wrong here? feel like i have following the documentation from top to toe

Your code looks correct, so it is probably a problem with your import path. Is your enum definition in the same module as your table! macro? If not you'll need to import it

Your code looks correct, so it is probably a problem with your import path. Is your table! macro is the same module as your enum definition? If not you'll need to import it.

Moving the Enums into the schema file complete solved it! Thank you!