Skip to content

Assign belongs_to params to the association - #583

Closed
excid3 wants to merge 1 commit into
mainfrom
assign-belongs-to-params
Closed

excid3 wants to merge 1 commit into
mainfrom
assign-belongs-to-params

Conversation

@excid3

@excid3 excid3 commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Notifier.with(record: ...) assigns the record association and stores everything else in params. Apps that add another belongs_to to Noticed::Event, for example an account to scope events by tenant, have had to override with to pull it out of params and assign it themselves. Jumpstart Pro does this in an initializer, and it's the most common reason people add columns to noticed_events.

Now any param named after a belongs_to association on the notifier is assigned the same way record is:

class ApplicationNotifier < Noticed::Event
  belongs_to :account
end

CommentNotifier.with(account: @account, record: @comment, foo: "bar")
# => event.account == @account, event.record == @comment, event.params == {foo: "bar"}

Only belongs_to names are matched, so a param that happens to share a name with a column like type or params is left alone. Ephemeral notifiers are unchanged.

Adds a test with an AccountNotifier in the dummy app, a README note under the record: explanation, and a changelog entry.

https://claude.ai/code/session_013hc6NU5mH5ytMmHbiEVtK5

`with(record: ...)` assigned the record association and everything else
went into params. Apps that add another belongs_to to Noticed::Event,
such as an account to scope events by tenant, had to override `with`
to pull it out of params themselves. Now any param named after a
belongs_to association on the notifier is assigned the same way record
is.

Claude-Session: https://claude.ai/code/session_013hc6NU5mH5ytMmHbiEVtK5
@excid3

excid3 commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Closing this. Apps that need a default (like Jumpstart Pro's Current.account fallback) still have to override with, and that override can simply call super, so this saves very little. It isn't worth the breaking change for apps that already have a same-named association and read it from params.

@excid3 excid3 closed this Oct 1, 2026
@excid3
excid3 deleted the assign-belongs-to-params branch October 1, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant