-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Should the changes be available in after-update
?
#129
Comments
This would be helpful to me. I have logic that I want to fire when a particular column has changed. If I do it in I don't have strong feelings about whether I get them via |
So this does seem to work sometimes (as proven by #171) but in other situations it doesn't... in Metabase for example something with the (toucan2.core/define-after-update :model/User
[user]
(println "ORIGINAL =>" (select-keys (toucan2.core/original user) [:is_superuser]))
(println "NEW =>" (select-keys user [:is_superuser]))
(println "CHANGES =>" (select-keys (toucan2.core/changes user) [:is_superuser]))
user)
(defn x []
(let [user (toucan2.core/select-one :model/User)
_ (println "USER =>" (select-keys user [:is_superuser]))
updates {:is_superuser (not (:is_superuser user))}
_ (println "UPDATES =>" updates)
rows-updated (toucan2.core/update! :model/User (:id user) updates)]
(printf "Updated %d rows.\n" rows-updated)))
(x)
USER => {:is_superuser true}
UPDATES => {:is_superuser false}
ORIGINAL => {:is_superuser false}
NEW => {:is_superuser false}
CHANGES => {}
Updated 1 rows. vs. a new model, which works correctly (methodical.core/defmethod toucan2.core/table-name ::FakeUser
[_model]
"core_user")
(toucan2.core/define-after-update ::FakeUser
[user]
(println "ORIGINAL =>" (select-keys (toucan2.core/original user) [:is_superuser]))
(println "NEW =>" (select-keys user [:is_superuser]))
(println "CHANGES =>" (select-keys (toucan2.core/changes user) [:is_superuser]))
user)
(defn x []
(let [user (toucan2.core/select-one ::FakeUser)
_ (println "USER =>" (select-keys user [:is_superuser]))
updates {:is_superuser (not (:is_superuser user))}
_ (println "UPDATES =>" updates)
rows-updated (toucan2.core/update! ::FakeUser (:id user) updates)]
(printf "Updated %d rows.\n" rows-updated)))
(x)
USER => {:is_superuser false}
UPDATES => {:is_superuser true}
ORIGINAL => {}
NEW => {:is_superuser true}
CHANGES => {:is_superuser true}
Updated 1 rows. Not sure why |
Seems like an underlying issue is that ORIGINAL is wrong: in your example it should be |
Use case: to log all the changes that were made to rows in the application database.
If there were some way to make the changes made available, or at least the ones made by Toucan -- probably ok to ignore ones done by DB triggers like
ON UPDATE SET updated_at = now()
, that could be useful. Could these be made available by a&changes
anaphor in the after-update method? Or shouldafter-update
just see an instance with thet2/changes
? Need to think about this.The text was updated successfully, but these errors were encountered: