Replies: 1 comment
-
|
Hey @adamnoto! 👋 There is no such feature in Marten at the moment. I will say that there are cons to implicit behaviours like the one you are suggesting (eg. what if you want to add a team division without triggering email sending? eg. while backfiling some data?). For these reasons, I would recommend defining your orchestration logic (adding records to associations and triggering emails) explicitly in a dedicated method or a dedicated abstraction (eg. service abstraction, operation, etc). Ideally you want to minimize the side effects induced by low level record operations (such as adding a record to a many-to-many association). Otherwise you are at risk of having these side effects being applied in situations in which you probably don't want to have them applied (e.g., backfilling, migrations, bulk imports). Now I am not opposed to adding something like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes, we want to wrap some logic around when an association is changed. I think this is a very valid use case.
Assume we have this class, where we want to automatically send an email when a division is updated, for review purpose.
If we do
employee.team_divisions.add(team_division), the employee class has no idea that its association has changed thus we couldn't trigger the email sending, sinceafter_updateis not called. To send the review email, currently we define anadd_team_divisionmethod, but this is definitely error-prone as we may forget its existence and callteam_divisions.addinstead.This is a sketchy scenario indeed, we may argue "why not just send the email in the controller" or that it's best practice to do that instead of this. But yeah, I think it's such a common business case to wrap custom logic when relationship changes -- I can cite real business case example, but I am afraid I'd violate some agreements by doing so.
In Rails, they have something like
touch. How about in Marten? Should we implement something like that, or do we already have a similar feature?Beta Was this translation helpful? Give feedback.
All reactions