Skip to content

Conversation

@LucaCappelletti94
Copy link
Contributor

As per discussion #4870

@weiznich weiznich requested a review from a team November 17, 2025 13:41
@LucaCappelletti94
Copy link
Contributor Author

Why doesn't Column implement HasTable?

@weiznich
Copy link
Member

weiznich commented Dec 1, 2025

Columns likely don't implement HasTable because this trait is mostly applied to rust side "model" structs and not sql side zero sized types. If it's reasonably possible to add a impl<C> HasTable for C where T: Column it might be acceptable to add it. If it requires us generating this impl for each column that will likely increase the size of the schema.rs file, which should be avoided.

@LucaCappelletti94
Copy link
Contributor Author

Columns likely don't implement HasTable because this trait is mostly applied to rust side "model" structs and not sql side zero sized types. If it's reasonably possible to add a impl<C> HasTable for C where T: Column it might be acceptable to add it. If it requires us generating this impl for each column that will likely increase the size of the schema.rs file, which should be avoided.

Will try to do as you suggest.

@LucaCappelletti94
Copy link
Contributor Author

Since there is already the following blanket:

impl<T: HasTable> HasTable for &T {
    type Table = T::Table;

    fn table() -> Self::Table {
        T::table()
    }
}

The proposed blanket impl<C> HasTable for C where T: Column is not implementable as:

conflicting implementations of trait `HasTable` for type `&_`
downstream crates may implement trait `query_source::Column` for type `&_`

So we can either have a tuple where all entries have HasTable implementing HasTable, or a tuple where all entries implement Column having HasTable. I believe that the first option should be the preferable one, and then a user is always free to add a macro which generates the HasTable trait for all columns. I wonder whether there should be a feature or variant of the table! macro to enable such a thing in diesel.

@weiznich
Copy link
Member

weiznich commented Dec 5, 2025

Sounds reasonable

@LucaCappelletti94
Copy link
Contributor Author

@weiznich the PR should be ready, even though due to the inability to implement the HasTable trait for C: Column it falls rather short from its initial objective.

While I agree it would be disagreeable to extend by default the schema size by implementing HasTable for all columns, would it be acceptable to do so with an optional feature gate (e.g. "column-has-table")?

@LucaCappelletti94
Copy link
Contributor Author

I tried to do the above, but it leads to a cascade of:

ambiguous associated type `Table` in bounds of `TypedColumn`
associated type `Table` could derive from `HasTable`
associated type `Table` could derive from `Column`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants