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

Flattening #14

Open
Korbeil opened this issue Oct 23, 2023 · 2 comments
Open

Flattening #14

Korbeil opened this issue Oct 23, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@Korbeil
Copy link
Member

Korbeil commented Oct 23, 2023

Inspired from https://docs.automapper.org/en/stable/Flattening.html

The idea is to makes simpler DTO compared to your source entities (or whatever your source is).
Let's do a quick example:

// source
class User
{
  public string $email;
}

class Order
{
  public string $reference;
  public User $customer;
}

// target
class OrderDTO
{
  public string $reference;
  public string $customerEmail;
}

$customer = new User();
$customer->email = '[email protected]';
$source = new Order();
$source->reference = 'FAC9123';
$source->customer = $customer;

dump($autoMapper->map($source, OrderDTO::class));

// Will output:
//
// OrderDTO {#14 🔽
//  +reference: "FAC9123"
//  +customerEmail: "[email protected]"
// }

Idea is to flatten the objects so they can be mapped to a property with a name matching their path, in this example we have "Order -> customer (User) -> email" that is flatten to "Order -> customerEmail"

@nikophil nikophil mentioned this issue Dec 11, 2023
6 tasks
@joelwurtz joelwurtz added the enhancement New feature or request label Mar 23, 2024
@joelwurtz
Copy link
Member

I think this can be done with transformer and expression language now ?

Like :

class Order
{
  public string $reference;
  #[MapTo(OrderDTO::class, name: 'customerEmail', transformer: 'source.customer.email')]
  public User $customer;
}

Do we want to add more than that ? (I think it will be pretty complicated, so i would say no)

@Korbeil
Copy link
Member Author

Korbeil commented Mar 31, 2024

I would like it to be some kind of configuration and it will do flattening automatically without the need to make attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants