sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

sea-orm-cli: allow skipping impl ActiveModelBehavior for generated entities

Open waynr opened this issue 1 year ago • 10 comments

This PR adds an option that enables users to skip generating the

impl ActiveModelBehavior for ActiveModel {}

by passing the --gen-impl-active-model-behavior false flag to sea-orm-cli generate entity.

This is intended to allow for an easy and idiomatic-for-rust alternative to https://github.com/SeaQL/sea-orm/issues/1931 which I described in more detail in a related discussion post

I don't necessarily think this should close out #1931, but I do think that the complexity of the solution described in that issue merits some consideration given the available alternative.

waynr avatar Oct 30 '23 16:10 waynr

The current state of this PR only adds the CLI flag that maintains the current default behavior and updates EntityWriter test cases to include the new option. If maintainers are open to this approach I'd be happy to add some new test cases to validate the false code path.

waynr avatar Oct 30 '23 17:10 waynr

I think this is an excellent solution.

dave42w avatar Oct 30 '23 18:10 dave42w

Something I didn't realize when I opened this PR is that it may be a little problematic since it's all-or-nothing whereas it may be desirable for the empty impl blocks to exist for some of the generated entities since some ActiveModel trait methods have ActiveModelBehavior as a trait bound: https://docs.rs/sea-orm/latest/sea_orm/entity/trait.ActiveModelTrait.html

waynr avatar Oct 30 '23 20:10 waynr

The implementation looks good, and this feature is definitely useful!

tyt2y3 avatar Oct 31 '23 11:10 tyt2y3

Hi this great, much needed, can we merge this?

jondot avatar Nov 27 '23 08:11 jondot

@waynr do you have anything to amend? I can probably merge it as is

tyt2y3 avatar Nov 27 '23 10:11 tyt2y3

Any updates?

LockedThread avatar Jul 10 '24 16:07 LockedThread

Oh I don't have any additional changes. Sorry, I lost track of this after I started a new job earlier this year.

waynr avatar Jul 10 '24 20:07 waynr

I've rebased onto master branch and resolved the merge conflict so this should be ready to merge.

waynr avatar Jul 10 '24 20:07 waynr