Replies: 5 comments 8 replies
-
What is the final intended API? |
Beta Was this translation helpful? Give feedback.
-
Hello, I have a question related to this: Suppose that I have an Active Model I want to use for updating a record. Not every value in the active model needs to be present, because I just need to update two columns. My understanding is that my active model needs to have the primary key filled (otherwise the update wouldn't be aware of what should be updated), plus the two columns I am interested in updating. So that: for this model
If I need to update phone and address for a given record I would have
Assuming this is true, ghere are some questions:
Suppose that I have a batch of users to activate. It would be much more fluent to do
Ratter than use columns expressions for everything, needing to specify their types, because activeValue already has everything we need to build safely a record in terms of types. Thanks, Marlon |
Beta Was this translation helpful? Give feedback.
-
Hello, There are several update's functions around, so this is probably confusing me. The default implementation of update from ActiveModelTrait for example returns Self, so that I can not access the rows_affected because I am not calling exec on the entity, either this or generics all around the place are naking me confused. As far as I understood (with 0.2.2) the update from ActiveModelTrait calls Entity::update(self).exec(db); and this exec returns the original record. |
Beta Was this translation helpful? Give feedback.
-
Thanks. The question though is ... what if the rrow doesn't exist when you call update()? Will an error be triggered in the update function? This is what I miss in the documentation. |
Beta Was this translation helpful? Give feedback.
-
Yes, this would be great, and this is why I asked in the first place. Why? Because update() can be used with filters. One might, for example, update a record but only if some column of itself still has some value set. example: MyEntity::update(ActiveRecord {
id: Set(5),
status: Set("ACTIVE"),
})
.filter(column::Status.eq("READY_FOR_ACTIVATION")
.exec(&db)
.await This is useful to handle idempotency problems: I want to update status but only if, in the meantime, it hasn't yet been updated by another oprocess or something similar. In this situation (or if I provide an id which does not exist) I have to know if my update has occurred successfully. One can arg that I could use update_many, but using update gives me the advantage to have the active model itself be returned, which as far as I understand is not the case with update_many. |
Beta Was this translation helpful? Give feedback.
-
To avoid manually
exec
the insertActiveModel
. In below, we cannot simplysave
it because this is a junction table and the composite primary key should be set during insert.sea-orm/tests/relational_tests.rs
Lines 562 to 569 in bfaa7d4
Perhaps
impl
it heresea-orm/sea-orm-macros/src/derives/active_model.rs
Lines 39 to 47 in 8cfa142
Beta Was this translation helpful? Give feedback.
All reactions