Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining multiple SOURCEs into one single TARGET #149

Open
herna opened this issue Nov 2, 2023 · 2 comments
Open

Combining multiple SOURCEs into one single TARGET #149

herna opened this issue Nov 2, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@herna
Copy link

herna commented Nov 2, 2023

Hi,

I don't know if there's a workaround for this.

In my project I have the case where one single class (form) is a combination of several other classes (model objects that reflect tables from the database).

I have for example these 2 models:

@freezed
class EquipmentBase with _$EquipmentBase {
  const factory EquipmentBase({
    required int id,
    required String name,
  }) = _EquipmentBase;
}

@freezed
class Equipment with _$Equipment {
  const factory Equipment({
    required int id,
    required int type,
  }) = _Equipment;
}

And this single form object:

@freezed
class EquipmentForm with _$EquipmentForm {
  const factory EquipmentForm({
    required int id,
    required String name,
    required int type,
  }) = _EquipmentForm;
}

I'd like to be able to get an EquipmentForm (TARGET) based on both Equipment and EquipmentBase (SOURCES)

At the moment I just make a double conversion and combine manually the properties at the end:

  • Convert EquipmentBase to EquipmentForm
  • Convert Equipment to EquipmentForm
  • Use copyWith() to combine both EquipmentForm objects

Is there anyway I can do this at the moment? Maybe through a custom converter or similar?

Thanks.

@herna herna added the enhancement New feature or request label Nov 2, 2023
@tenhobi
Copy link
Member

tenhobi commented Nov 2, 2023

Hi, at the moment, no. We would like to support this case with normal classes. (not for sealed/freezed, reasons similar to #148).

The implementation could be done for N input classes to 1 output, probably as a new MapTypeMultiple or something like that. But in the near future, I don't think we will have enough time to implement that.

You are, however, free to take the initiative if you'd like to!

@herna
Copy link
Author

herna commented Nov 2, 2023

Thanks @tenhobi

Not a big deal for me at the moment either, just an improvement for the future.

@tenhobi tenhobi added the good first issue Good for newcomers label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants