You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But an empty struct is not supported by diesel's AsChangeset and Insertable.
Sadly, the current trait Model definition requires every model to have a changeset type implementing AsChangeset (and should also require Insertable tbh).
Relax the bound AsChangeset of trait Model. We can do this since the queries are generated by the macro and we don't rely on generic type parameters. So this bound is not strictly necessary.
Generate and empty changeset struct that doesn't derive(AsChangeset, Insertable).
Generate a different implementation for create and update operations if the model that's being expanded contains no non-PK field.
create and create_batch could use .default_values() expression method
updates don't need to be implemented as PK changes is out of ModelV2's scope
If derive(ModelV2) is applied to a struct that only contains a PK, the macro can change its ImplPlan to avoid generating the Update* impl blocks. If those were asked explicitly, an error should be raised.
Description and goal
We want the following code to work:
It currently fails because the macro generate the following changeset definition:
But an empty struct is not supported by diesel's
AsChangeset
andInsertable
.Sadly, the current
trait Model
definition requires every model to have a changeset type implementingAsChangeset
(and should also requireInsertable
tbh).🔧 Suggested fix
AsChangeset
oftrait Model
. We can do this since the queries are generated by the macro and we don't rely on generic type parameters. So this bound is not strictly necessary.derive(AsChangeset, Insertable)
.create
andcreate_batch
could use.default_values()
expression methodderive(ModelV2)
is applied to a struct that only contains a PK, the macro can change itsImplPlan
to avoid generating theUpdate*
impl blocks. If those were asked explicitly, an error should be raised.Acceptance criteria
compiles and works as expected
The text was updated successfully, but these errors were encountered: