Add :replace_all and :replace_all_except to upsert_fields

Ecto allows you to set a list of the fields you want to change, replace all fields or replace all fields except some.

AFAIK, Ash don’t seem to have the same options, you can only set the list of fields, this can be very bothersome if you have a resource with a bunch of fields.

Can we add these options so we can write an action like this?

    create :create do
      upsert? true
      upsert_identity :unique_id
      upsert_fields :replace_all
    end

or

    create :create do
      upsert? true
      upsert_identity :unique_id
      upsert_fields {:replace_all_except, [:some_field]}
    end

or

    create :create do
      upsert? true
      upsert_identity :unique_id
      upsert_fields {:replace, [:some_field]}
    end

Yes, we can add that. Please open an issue on the Ash repo. PRs welcome!

1 Like

I created a ticket: Add :replace_all and :replace_all_except to upsert_fields · Issue #760 · ash-project/ash · GitHub

I will take a look into the code.

1 Like

@zachdaniel here is my PR:

2 Likes

Thanks for the contribution @sezaru. Zach is away on a well deserved holiday for a few weeks and sadly he’s the most knowledgeable about how this all works. I’ll cast an eye over it but I don’t feel comfortable merging it without him taking a look.

No problem at all! I’m not in a hurry :slight_smile: