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

a few things #224

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

a few things #224

wants to merge 4 commits into from

Conversation

mayel
Copy link

@mayel mayel commented Jun 26, 2023

Hi, hope this helps!

@izelnakri
Copy link
Owner

izelnakri commented Jul 19, 2023

Hi @mayel , thanks for your contributions and making a description/list of changes! It would have been better if these changes were included in separate commits & PRs but I'm currently having a look.

2 comments raised & changes requested.

def update(changeset, options \\ @default_transaction_options) do
def update(changeset, options \\ @default_transaction_options)
def update(%Ecto.Changeset{changes: changes}, _) when changes==%{} do
{:ok, :no_changes}
Copy link
Owner

@izelnakri izelnakri Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ecto.Repo.update today returns {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}. Although I do see the benefit of having :no_changes atom return, I'd like to not diverge from the Ecto.Repo.update() return signature whenever possible: https://hexdocs.pm/ecto/Ecto.Repo.html#c:update/2

Can we change this to make it return like Ecto.Repo.update ? I endorse the solution otherwise

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wasn't quite happy with that either. What would you suggest instead? I'm not sure if/how we could return the schema when we're given just a changeset, and returning a changeset error seems odd when there wasn't really an error (but just no change to save).

Copy link
Author

@mayel mayel Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ecto docs state "by default, if there are no changes in the changeset, update/2 is a no-op" so I guess we can still call it and rely on it to return a schema, but skip inserting the version struct in PaperTrail.Multi.update/3 if the changeset's changes is empty...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ecto docs state "by default, if there are no changes in the changeset, update/2 is a no-op" so I guess we can still call it and rely on it to return a schema, but skip inserting the version struct in PaperTrail.Multi.update/3 if the changeset's changes is empty...

yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izelnakri done, that worked well :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants