-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Thoughts on using MODEL_id instead of MODEL as param #218
Comments
I'm fine with adding it as long as it's not a breaking change. Any idea how you envision that working? |
Something like |
Hmm, I feel like we could be more descriptive. Or maybe it needs to be a new method? has_noticed_notifications_by_id I'm not sure. |
Would it make sense to use the model's Global ID instead - that way there could still be some magic in converting that data back to an ActiveRecord instance if required? |
@dwightwatson That's already how it works using the ActiveJob coder. I don't think GlobalID would help for this stuff because the key is already going to denote the model name. |
I made this work in my project by adding a polymorphic subject field to the notifications table. Feels like it could be upstreamed. Improves the AR has_many_notifications logic a bit and removes the need to do a query on a jsonb field to get your associated notifications. create_table :notifications do |t|
t.references :recipient, polymorphic: true, null: false
t.references :subject, polymorphic: true
t.string :type, null: false
t.jsonb :params
t.datetime :read_at
t.timestamps
end
class Notification < ApplicationRecord
include Noticed::Model
belongs_to :recipient, polymorphic: true
belongs_to :subject, polymorphic: true
end
class MessageNotification < Noticed::Base
deliver_by :database, format: :format_database
def format_database
{
type: self.class.name,
params: params,
subject: params[:message]
}
end
end
class Message < ApplicationRecord
has_many :notifications, as: :subject, dependent: :destroy
end |
We are trying to use it with a multi-tenant system, with Any quick solution for our scenario? |
I think we just HAVE to avoid globalids and play on plain ids, we will try some monkey patching for now |
UPDATE: We are going en-route to send in ids instead of objects in recipients and overriding methods needed(mainly in the delivery_methods we are using, so far database and email had to be overriden) |
I have the same issue, and wondered if a very simple solution could an option to specify where to get the value from, e.g.:
Will happily create a PR for this :-) |
+1 |
Hello, @excid3 ! Happy to see a new version of this gem! |
Yep, see the part about the |
@excid3 Glad the polymorphic idea panned out. Been working well for us for over a year now. |
Seems like
noticed
serializes the entire param in the Notification record. I have some pretty chunky models; I don't really want to save a whole copy of them within each Notification.In some parts of my codebase, I've taken to using e.g.
params :lender_id
instead ofparams :lender
, and then just doing aLender.find
on the param when I need to get the Lender record back. This seems like it would be fine in quite a lot of circumstances.Is there any thought on which is preferred and why? I don't think
has_noticed_notification
works if usingMODEL_id
, but it seems like it would be a small change for it to be supported (which I could potentially make).The text was updated successfully, but these errors were encountered: