Skip to content

Use in Ecto Changeset pipeline #2

@byjpr

Description

@byjpr

Currently MapRewire returns both the original map and the new map. This means we need to create boilerplate to be able to use MapRewire in a pipeline:

  def changeset(variant, params) do
    variant
    |> normalize_data()
    |> cast(
      params,
      ~w(shopify_id title price weight compare_at_price requires_shipping sku available image_id option1 option2 option3)
    )
  end

  defp normalize_data(data) do
    [_old, new] = data <~> @transforms
    new
  end

To reduce the amount of boilerplate needed to use MapRewire we should consider creating a normalize_data function that can be used in a typical changeset:

  def changeset(variant, params) do
    variant
    |> normalize_data(params, @transforms)
    |> cast(
      params,
      ~w(shopify_id title price weight compare_at_price requires_shipping sku available image_id option1 option2 option3)
    )
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions