sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

Proposal: doBeforeUpdateHooks in SetRelation function

Open soolaimon opened this issue 6 years ago • 4 comments

I have a validation function I run as a BeforeUpdateHook on one model. It runs some checks an associated model (in the context of the local model), and it would improve code flow if I could rely on

Local.SetForeign(_, _, foreignObject)

rather than setting the foreign ID and calling local.Update.

I'd love to take a stab at this if you don't have any objections to it.

soolaimon avatar Dec 17 '18 23:12 soolaimon

You're saying you would like SetForeign to actually make a call to the database? I was fairly certain that that already occurs. Though I think I'm not understanding exactly what you're bringing up here.

aarondl avatar Dec 25 '18 17:12 aarondl

I'd like SetForeign to run beforeUpdateHooks, since it is actually updating the local table by setting a foreign key.

soolaimon avatar Dec 27 '18 16:12 soolaimon

Ah yes. I now understand. That's a very good point that hooks are not run for these special operations. It makes sense to do that.

It also makes sense at some point to be able to opt out of hooks and timestamps by using a context value. This is of course a separate change but I wanted to mention it because I've only just now thought of it seeing as we're adding hooks in places people might not expect (or at least is a change from what's happening now)

aarondl avatar Dec 31 '18 16:12 aarondl

FWIW I added new boil.SkipTimestamps and boil.SkipHooks features to compliment this change.

aarondl avatar Jan 02 '19 17:01 aarondl