Repository: diesel-rs/diesel
File: diesel_derives/src/model.rs (Rust)

Code before:
        let name = Ident::new(&infer_table_name(&ident.to_string()), ident.span()).into();

        Self {
            name,
            table_names,
            primary_key_names,
            treat_none_as_default_value,
            treat_none_as_null,
            belongs_to,
            sql_types,
            aggregate,
            not_sized,
            foreign_derive,
            mysql_type,
            sqlite_type,
            postgres_type,
            fields: fields_from_item_data(fields),
            check_for_backend,
        }
    }

    pub fn table_name(&self) -> &Path {
        match self.table_names.len() {
            0 => &self.name,
            1 => &self.table_names[0],
            _ => abort_call_site!("Multiple table name attributes are not supported"),
        }
    }

    pub fn table_names(&self) -> &[Path] {
        match self.table_names.len() {
            0 => from_ref(&self.name),
            _ => &self.table_names,
        }
    }

    pub fn fields(&self) -> &[Field] {
        &self.fields
    }

    pub fn find_column(&self, column_name: &Ident) -> &Field {
        self.fields()
            .iter()
            .find(|f| f.column_name() == *column_name)
            .unwrap_or_else(|| abort!(column_name, "No field with column name {}", column_name))
    }

    pub fn has_table_name_attribute(&self) -> bool {
        !self.table_names.is_empty()
    }


Review comment (suggestion):
```suggestion
            _ => abort_call_site!("expected a single table name attribute"),
```

Let's avoid erroring out on the call site. Let's try doing it on the spans for table names.

Code after:
                StructAttr::Aggregate(_) => aggregate = true,
                StructAttr::NotSized(_) => not_sized = true,
                StructAttr::ForeignDerive(_) => foreign_derive = true,
                StructAttr::MysqlType(_, val) => mysql_type = Some(val),
                StructAttr::SqliteType(_, val) => sqlite_type = Some(val),
                StructAttr::PostgresType(_, val) => postgres_type = Some(val),
                StructAttr::CheckForBackend(_, b) => {
                    check_for_backend = Some(b);
                }
            }
        }

        let name = Ident::new(&infer_table_name(&ident.to_string()), ident.span()).into();

        Self {
            name,
            table_names,
            primary_key_names,
            treat_none_as_default_value,
            treat_none_as_null,
            belongs_to,
            sql_types,
            aggregate,
            not_sized,
            foreign_derive,
            mysql_type,
            sqlite_type,
            postgres_type,
            fields: fields_from_item_data(fields),
            check_for_backend,
        }
    }

    pub fn table_names(&self) -> &[Path] {
        match self.table_names.len() {
            0 => from_ref(&self.name),
            _ => &self.table_names,
        }
    }

    pub fn fields(&self) -> &[Field] {
        &self.fields
    }

    pub fn find_column(&self, column_name: &Ident) -> &Field {
        self.fields()
            .iter()
            .find(|f| f.column_name() == *column_name)
            .unwrap_or_else(|| abort!(column_name, "No field with column name {}", column_name))
    }