Skip to content

Syntax Error when saving active model that sets nothing #1376

Closed

Description

@billy1624

Discussed in #1371

Originally posted by lihe07 January 8, 2023
I have a ActiveModel like this;

ActiveModel {
    id; Unchanged(1),
    name: NotSet,
    password: NotSet
}

The SQL query for saving this looks like that:

UPDATE
  `users`
SET
WHERE
  `users`.`id` = ?

And that leads to a syntax error (empty set section).

I'm considering whether it's sea-orm's task to determine if the ActiveModel does noting or not.

Activity

  1. billy1624 commented on Jan 9, 2023

    @billy1624
    MemberAuthor

    Hey @lihe07, thanks for bring this up to the spotlight. I think this is something that we need to "fix".

    IMO when updating / saving a existing ActiveModel with all its value being Unchanged or NotSet, the expected behaviour should be no-op. That's to skip firing any SQL statement.

    To achieve that we need to check the values field of sea_query::UpdateStatement is empty at executor/update.rs.

  2. lihe07 commented on Jan 9, 2023

    @lihe07

    @billy1624 Thanks! I'd be happy to work this out if I can!
    (and I don't need a patch for my project either)

  3. self-assigned this
    on Jan 10, 2023
  4. billy1624 commented on Jan 10, 2023

    @billy1624
    MemberAuthor

    Hey @lihe07, thanks for the interest!! Sorry, I didn't realise you want to take this. Please check my PR at #1384

  5. lihe07 commented on Jan 12, 2023

    @lihe07

    Never mind! I'll keep an eye out too, if there's anything I can do to help.

  6. added this to the 0.11.x milestone on Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions